0

I'm trying to filter a data using PHP. I'm able to filter using the key when there is only one key in the params. If there are multiple keys i get the value only for the last param.

Ex: In the request URL if the City=NY& Category=Population I get a proper value. When I add another param with same key i.e City=NY&Category=Population&City=SF I get the value for only SF where it should give me the sum of both NY and SF. The data is being pulled from a table.

My code is :

function search(array $array, array $search)
{

return array_filter($array, function ($item) use ($search) {

//print_r(array_intersect_assoc($search, $item));
print_r($item);
return array_intersect_assoc($search, $item) === $search;

});
}

$filteredarray = search($json_output, $query);
Syscall
  • 19,327
  • 10
  • 37
  • 52
noob92
  • 1
  • 2

0 Answers0