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