The following code doesn't work, nor it really should as, reference don't work for arrays. However, how else can I make it work?
The idea is to find an item in a multidemesional array by its key and access it directly, without iterating the array each time.
$humans[0]['human_id'] = 6;
$humans[0]['human_name'] = 'Harry Potter';
$humans[0]['human_items'][0]['item_id'] = 6;
$humans[0]['human_items'][0]['item_name'] = 'Wizard stick';
$item &= get_item($humans, 'item_id');
$item = '5';
function &get_item($array, $find_key)
{
foreach($array as $key => $array_item)
{
if(is_array($array_item))
{
$ret = get_item($array_item, $find_key);
if($ret)
return $ret;
}
else if($key == $find_key)
return $array_item;
}
}
What I am trying to do is to dynamically build an array representing a few multi_row queries results. In this example the array holds the result of two queries:
select from humans
and
select from items where item_id in (select * from humans)
If you know a ready class to handle such things, I'd be delighted to know.