[UPHPU] pluck out of array with index without rebuilding

Wade Preston Shearer wadeshearer.lists at me.com
Thu Jan 15 21:29:43 MST 2009


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?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2431 bytes
Desc: not available
Url : http://uphpu.org/pipermail/uphpu/attachments/20090115/45d56bf8/smime.bin


More information about the UPHPU mailing list