Jump to content

Surely a simple problem...


ViperSBT

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.
Link to comment
https://forums.phpfreaks.com/topic/19023-surely-a-simple-problem/
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]
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]

Archived

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

×
×
  • Create New...

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.