I need to filter an array in PHP but am not sure how to pass an argument to the callback. Essentially I have 2 comparisons to make on each item in the array.
// This data will be sent to the function as JSON so I'm "creating" the JSON here.
$data = json_encode(Array(
Array("StartDate"=>"2014/07/31","LocZipCode"=>"19406","LocationURL"=>"FSU","EventType"=>"UN"),
Array("StartDate"=>"2014/08/31","LocZipCode"=>"23513","LocationURL"=>"FSU","EventType"=>"UN"),
Array("StartDate"=>"2014/07/31","LocZipCode"=>"92108","LocationURL"=>"BU","EventType"=>"UN"),
Array("StartDate"=>"2014/09/30","LocZipCode"=>"78661","LocationURL"=>"BU","EventType"=>"UN")
));
// even using a global variable doesn't
// make it visible in getUniv() function
global $univ_seg;
$univ_seg = 'FSU';
getUA($data, $univ_seg);
function getUniv($var){
return($var["EventType"] == "UN" && $var["LocationURL"] == $univ_seg);
}
function getUA($data, $univ_seg) {
$univ_sched = json_decode($data, true);
$re = array_filter($univ_sched, "getUniv");
print_r($re);
}
I've also tried using a lambda but I just can't make it work. Any ideas??