/**
* Sort data (for fun)
*
* @param array|string $input
* @param string $pattern
* @return array
*/
function search($input, $pattern) {
if (is_string($input))
$input = json_decode($input);
$clean = [];
foreach($input as $item) {
if($item->lastName == $pattern) {
$clean[] = $item;
}
}
if(count($clean) > 1)
foreach($clean as $key => $value) {
$cmpDate[$key] = date($value->birth);
}
$clean[] = array_multisort($cmpDate, SORT_ASC, $clean);
return array_values($clean)[0];
}
var_dump(search($json, 'Doe'));