title: filter an array from mysql_query result by value
body: <p>So... I am PHP dummie and I am trying to filter an array.</p>
  
  <p>I have the following php function to retrieve data from MYSQL </p>
  
  <pre><code>function hook_plan1($vars){
    $result = mysql_query("SELECT * FROM tblpricing WHERE relid=12 AND type='product'");
    $products = array();
      while( $data = mysql_fetch_assoc($result)){
      array_push($products, $data);
      }
    return array(
    "plan1" =&gt; $products);
  }
  </code></pre>
  
  <p>That function renders the following array:</p>
  
  <pre><code>-&gt;plan1 = Array (7)
    0 =&gt; Array (16)
      id =&gt; "71"
      type =&gt; "product"
      currency =&gt; "1"
      ...
    1 =&gt; Array (16)
      id =&gt; "80"
      type =&gt; "product"
      currency =&gt; "3"
      ...
    2 =&gt; Array (16)
      id =&gt; "402"
      type =&gt; "product"
      currency =&gt; "14"
      ...
  </code></pre>
  
  <p>I would like to filter that array by "currency" (which comes in the $_SESSION) so I can get a single array, something like this:</p>
  
  <pre><code>-&gt;plan1 = Array (16)
      id =&gt; "402"
      type =&gt; "product"
      currency =&gt; "14"
      ...
  </code></pre>
  
  <p>I was pretty sure it was easy, so I tried the following array filter:</p>
  
  <pre><code>function hook_plan1($vars){
    $currency_id = $_SESSION['currency'];//this is a number
    $result = mysql_query("SELECT * FROM tblpricing WHERE relid=12 AND type='product'");
    while ($data = mysql_fetch_assoc($result)) {
      $products = $data;
    }
    $filter = (is_array($products) &amp;&amp; $products['currency'] == $currency_id);
    $filtered_product = (array_filter($products, $filter));
    return array(
      "plan1" =&gt; $filtered_product);
  }
  </code></pre>
  
  <p>But it doesn't work :(
  Any ideas?</p>