Jump to content

Archived

This topic is now archived and is closed to further replies.

ViperSBT

Surely a simple problem...

Recommended Posts

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.

Share this post


Link to post
Share on other sites
$states = Array ( [0] => Array ( [0] => 5 [1] => 30 ) )

As for the series of ArrayArray...  The foreach is inside a while loop...

Share this post


Link to post
Share on other sites
[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]
<?php
foreach ($states as $state) echo "$state[1]<br />\n";
?>
[/code]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.