I was working on an API for ustream which returns the following array
Array
(
[results] => Array
(
[0] => Array
(
You could use iterators to make your function a whole lot easier:
function findSourceChannel($array)
{
foreach (new RecursiveIteratorIterator(new RecursiveArrayIterator($array)) as $key => $value) {
if ($key == 'sourceChannel') {
return $value['id'];
}
}
return null;
}
That said, I'm not sure why you can't just do a search like this:
foreach ($array['results'] as $result) {
if (isset($result['sourceChannel'])) {
return $result['sourceChannel']['id'];
}
}
return null;