I have a json array in a json file, this is brought into a $data variable $data = file_get_contents("json/data.json");. Two of the attribute names are commonName and elementName, these will be passed through the url.
With the json file in the data variable I would like to filter on two attributes and then echo the result.
I'm getting the following error:
Warning: array_filter() expects parameter 1 to be array, string given in
Here's my current code:
<?php
function myfilter($row){
return ($row['commonName']=='goat' && $row['elementName']=='calcaneus');
}
$result = array_filter($data, 'myfilter');
echo '<pre>';
echo 'json array{';
foreach($result as $elem) {
echo(
$elem['institutionID']. ", ".
$elem['scientificNameID']. ", ".
$elem['scientificName']. ", ".
$elem['kingdom']. ", ".
$elem['phylum']. ", ".
$elem['class']. ", ".
$elem['order']. ", ".
$elem['family']. ", ".
$elem['genus']. ", ".
$elem['subgenus']
);
echo("<br/>");
}
echo '</pre>';
//
echo '}';
?>
edit:
original json code snippet:
[
{
"type": "",
"modified": "",
"language": "",
"license": "",
"rightsHolder": "",
"accessRights": "",
"bibliographicCitation": "",
"references": "",
"institutionID": "Phoneome10k",
"collectionID": "",
"datasetID": "",
"institutionCode": "",
"collectionCode": "",
"datasetName": "",
...