[thelist] getting selective variables out of an array()
Fred Jones
fredthejonester at gmail.com
Mon Jan 11 12:43:02 CST 2010
Should be:
foreach ($element as $item)
{
foreach ($item as $key => $element )
{
...
On Mon, Jan 11, 2010 at 8:40 PM, Bob Meetin <bobm at dottedi.biz> wrote:
> Fred Jones wrote:
>>>
>>> <?php
>>> $states = array(
>>> array ( "abbr" => "AL", "name" => "Alabama" ),
>>> array ( "abbr" => "AK", "name" => "Alaska" ),
>>> array ( "abbr" => "AZ", "name" => "Arizona" )
>>> )
>>>
>>> foreach ($states as $key => $element )
>>> {
>>> foreach ($element as $item)
>>> {
>>> print "$item<br />"; // this prints both $abbr ad $name
>>> // How do I print or set a variable for each item, abbr vs name?
>>> }
>>> }
>>> ?>
>>>
>>
>> Switch your foreache statements and then use:
>>
>> print "$key $element";
>>
>
> Thanks but unless I misconstrued the instructions, this doesn't work:
>
> see: http://www.dottedi.biz/codesamples/arrays
>
> Both .php and .txt version
>
> -Bob
>
> --
>
> * * Please support the community that supports you. * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !
>
More information about the thelist
mailing list