Using php's array_search on an array of objects
<p><a href="http://php.net/manual/en/function.array-search.php" rel="noreferrer">http://php.net/manual/en/function.array-search.php</a> allows me to find the first array key based on an array value.</p>

<p>Can this be accomplished with a single PHP function if the value is nested in an object in the array values, or must it be manually performed as I show below?</p>

<p>Thank you</p>

<pre><code>&lt;?php
function getKeyBasedOnName($arr,$name)
{
    foreach($arr as $key=&gt;$o) {
        if($o-&gt;name==$name) return $key;
    }
    return false;
}
$json='[
{
"name": "zero",
"data": [107, 31, 635, 203, 2]
},
{
"name": "one",
"data": [133, 156, 947, 408, 6]
},
{"name": "two",
"data": [1052, 954, 4250, 740, 38]
}
]';
$arr=json_decode($json);
var_dump(getKeyBasedOnName($arr,'zero')); //Return 0  
var_dump(getKeyBasedOnName($arr,'one')); //Return 1  
var_dump(getKeyBasedOnName($arr,'two')); //Return 2
var_dump(getKeyBasedOnName($arr,'three')); //Return false
</code></pre>