Re: Array question
| From: | Jeff Warrington | Date: | Wed, 16 Aug 2000 17:08:25 +0000 |
| Subject: | Re: Array question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-12066@lists.php.net to get a copy of this message | ||
In article
<F99F3F7C7049D211BC700008C7B1F0900759AB4F@texas.econophone.com>,
jay.paulson@viatel.com ("Paulson, Joseph V. \"Jay\"") wrote:
> hello everyone!
>
> I have a quick question about declaring an array. Below is the code
> snippet that I am dealing with. What happens when i traverse the
> $select["options"] position I only get the last two positions of the
> $selectOptions array. Obviously, I need it to traverse all the positions
> in the $select["options"] array. I don't have a clue as to why this is
> only traversing the last two positions (no matter how many elements are
> in the array), but any help would be greatly appreciated!
>
> $selectOptions = array("label"=>";lkj",
> "value"=>"l;kj;",
> "label"=>"canada",
> "value"=>"Canada", "label"=>"usa",
> "value"=>"USA");
>
Your array only has two hash keys: 'label' and 'value'. Your assignments
of valus of 'canada' and 'usa' for the 'label' key simply replace the
value of the previously defined hash element. Sounds like you need
something more like:
$selectOptions["label"][0] = ";lkj";
$selectOptions["label"][1] = "l;kj";
$selectOptions["label"][2] = "canada";
etc...
Jeff
$select = array("type"=>"select", "name"=>"select",
"value"=>"canada",
> "options"=>$selectOptions);
>
> reset($select["options"]); while (list($key, $value) =
> each($select["options"])){
> $debugMsg .= "select[\"".$key."\"] =
> ".$value."<br>\n";
> }
> echo $debugMsg;
>
> Thanks, Jay Paulson
>
> ps I am running PHP version 3.0.15
>