I have a following json:
$json = '[{"name":"Peter","bday":"1990-10-10"},{"name":"Mark","bday":"1992-08-10"},{"name":"John","bday":"1993-08-09"},{"name":"John","bday":"2000-05-19"}]';
Are names and Birthdays. Is there any way to use a criteria to search birthdays without foreach?
For example, "all registry with birthdays after 1993-01-01
".
Thanks
I was able to do this with array_filter
function
function greater_than($arr){
$date = $arr['bday'];
if(strtotime($date) > strtotime('1993-01-01')){
return $date;
}
}
$json = '[{"name":"Peter","bday":"1990-10-10"},{"name":"Mark","bday":"1992-08-10"},{"name":"John","bday":"1993-08-09"},{"name":"John","bday":"2000-05-19"}]';
$dec = json_decode($json,true);
print_r(array_filter($dec, "greater_than"));