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?
>
With the second array:
$food[] = array('id' => 1, 'name' => 'banana');
$food[] = array('id' => 2, 'name' => 'taco');
$food[] = array('id' => 3, 'name' => 'toast');
Why can't you do something like ...
echo 'Today we will be eating '.$food[food_id]['name'];
...
>
>
> --
> Scott Hill
>
> Food for thought:
> A good pun is it's own reword.
> Energizer bunny arrested! Charged with battery!
> A pessimist's blood type is always B-negative.
> 42.7 percent of all statistics are made up on the spot.
> How much deeper would the ocean be without sponges?
> Atheism is a non-prophet organization.
>
_______________________________________________
UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net