ViperSBT Posted August 29, 2006 Share Posted August 29, 2006 OK, I pass an array from another page, I then use the following code to handle the array:[code]foreach($states as $state){ echo $state;}[/code]I would expect to get each of the states in the array returned, instead what I get is:[quote]ArrayArrayArrayArray[/quote]So, why isn't the array being parsed? If I do print_r($states) I can see each of the elements in the array and they hold the correct value... So it seems the foreach isn't doing what it is supposed. Quote Link to comment Share on other sites More sharing options...
Jenk Posted August 29, 2006 Share Posted August 29, 2006 $states is an array of arrays. Quote Link to comment Share on other sites More sharing options...
ViperSBT Posted August 29, 2006 Author Share Posted August 29, 2006 $states = Array ( [0] => Array ( [0] => 5 [1] => 30 ) )As for the series of ArrayArray... The foreach is inside a while loop... Quote Link to comment Share on other sites More sharing options...
obsidian Posted August 29, 2006 Share Posted August 29, 2006 [quote author=ViperSBT link=topic=106096.msg424057#msg424057 date=1156865065]OK, I pass an array from another page, I then use the following code to handle the array:[code]foreach($states as $state){ echo $state;}[/code]I would expect to get each of the states in the array returned, instead what I get is:[quote]ArrayArrayArrayArray[/quote]So, why isn't the array being parsed? If I do print_r($states) I can see each of the elements in the array and they hold the correct value... So it seems the foreach isn't doing what it is supposed.[/quote]as jenk said, your values are being held within another level of arrays, so you need to access them that way. looks like you could probably simply do the following:[code]<?phpforeach ($states as $state) echo "$state[1]<br />\n";?>[/code] Quote Link to comment Share on other sites More sharing options...
ober Posted August 29, 2006 Share Posted August 29, 2006 If that is how you are building the $states array, you can't use a simple foreach loop to echo the results. 2D arrays have to be echoed how they are built, using both dimensions. Quote Link to comment Share on other sites More sharing options...
ViperSBT Posted August 29, 2006 Author Share Posted August 29, 2006 The $states array is bein gbuilt from a Mutli-Seelction List field on a prior page. The select which states they want to see a report for.[code]<select multiple name='states[]' size='10'> <option value='All' SELECTED>All States/Provinces</option> <? foreach ($statelist as $key => $value) { echo "<option value='" .$key."'>$statelist[$key]</option>\n"; } ?></select>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.