I would solve that by setting up the array like this...

$food = array(0 => array('name' => 'banana'), 1 => array('name' =>
'taco'), 2 => array('name' => 'toast'));

Then, your foreach would be the following:

foreach($menus as $menu) {
       echo 'Today will will be eating ' . $food[$menu['food_id']]['name'];
}

Craig Jackson

On Thu, Jan 15, 2009 at 9:29 PM, Wade Preston Shearer
<[email protected]> wrote:
> With the index, you can pluck a value out of an array, like this:
>
> $food = array(0 => 'banana', 1 => 'taco', 2 => 'toast');
>
> foreach($menus as $menu) {
>        echo 'Today will will be eating ' . $food[$menu['food_id']];
> }
>
>
> But if my food array looks like this…
>
> $food[] = array('id' => 1, 'name' => 'banana');
> $food[] = array('id' => 2, 'name' => 'taco');
> $food[] = array('id' => 3, 'name' => 'toast');
>
>
> …it's not possible unless you do this first…
>
> foreach($food as $item) {
>        $food_notmulti[$item['id']] = $item['name'];
> }
>
>
> …to flatten it.
>
> Or am I wrong? Is there a way to "pluck" from the multi-dimensional array
> where the ID is not an index?
>
> _______________________________________________
>
> UPHPU mailing list
> [email protected]
> http://uphpu.org/mailman/listinfo/uphpu
> IRC: #uphpu on irc.freenode.net
>


_______________________________________________

UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net

Reply via email to