Jump to content

Parsing through a dynamically created array

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
newphp

newphp

    Newbie

  • Members
  • Pip
  • 3 posts
I'm creating forms and input boxes on a page dynamically, and passing the inputs with an array to another page. The only problem is, once I get the array, I don't know how to read it! I know how to read a basic array, but the problem is my index is always different:

Array ( [index1_23] => [index2_23] => [index3_23] => [indext4_23] => [index5_23] =>7 [index1_24] => [index2_24] => [index3_24] => [indext4_24] => [index5_24] =>15 )

What I want to do is parse through this with PHP (i'm assuming) so that I can pull the index as a variable, and the ID at the end as a variable.

Ultimately what I want to break out into variable is:
$index = $_POST['index1_']
$id = $_POST['23']

Unfortunatley I can't seem to find an example to tell me how to just read the beginning of the array, and then the end.

Hope this make sense and thanks in advance!

#2
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
easiest is to run through the array with a
foreach ((array)$_POST as $key => $val) 
then, inside this loop, you get the key for each part in $key, and the value in $val
now you can treat the key as a normal variable and look for parts of the string, and act according to the key or the value...
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#3
newphp

newphp

    Newbie

  • Members
  • Pip
  • 3 posts
Thanks! I'll give that a try!