Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_php thread: Looping through TWO dimension array HELP


Message #1 by "jorge" <jorge@d...> on Tue, 29 Oct 2002 17:02:53 -0600
You're trying to overwrite the value of $_POST in first foreach() loop.

Also, your loop leads me to believe that your $_POST array looks something like
this:


_POST: Array
(
  [key1] =>  Array
  (
     [0]   =>  valueA
     [1]   =>  valueB
     [2]   =>  valueC
  )
  [key2] =>  Array
  (
     [0]   =>  valueD
     [1]   =>  valueE
     [2]   =>  valueF
  )
)


The reason I say this is because you only extract the key part of the key/value
pair in the first level of nesting.  Therefore, I can only guess that the keys
in your nested arrays are unimportant, and therefore just numeric.

If this is the case, you'll want this kind of loop:

foreach($_POST as $key => $nested)
{
  foreach($nested as $value)
  {
     ...
  }
}


Furthermore, since you're getting an error message in the 2nd foreach() call,
I'm led to believe that $_POST is no longer an array -- that is, when you
overwrite $_POST in the outer foreach() loop, you're assigning a scalar value.
A scalar value just means "not an array", in this context.


You should make heavy use of the print_r() function to fully understand the
structure of your $_POST array before attempting to traverse it looking for
specific key/value pairs.


Hope this helps,

Nik


  Return to Index