title: Count specific values in multidimensional array
body: <p>I'm trying to count the number of times a certain value appears in my multidimensional array based on a condition. Here's an example array;</p>
  
  <pre><code>$fruit = array (
                   "oranges" =&gt; array(
                                      "name"    =&gt; "Orange",
                                      "color"   =&gt; "orange",
                                      "taste"   =&gt; "sweet",
                                      "healthy" =&gt; "yes"
                                ),
                   "apples" =&gt; array(
                                      "name"    =&gt; "Apple",
                                      "color"   =&gt; "green",
                                      "taste"   =&gt; "sweet",
                                      "healthy" =&gt; "yes"
                                ),
                   "bananas" =&gt; array(
                                      "name"    =&gt; "Banana",
                                      "color"   =&gt; "yellow",
                                      "taste"   =&gt; "sweet",
                                      "healthy" =&gt; "yes"
                                ),
                   "grapes" =&gt; array(
                                      "name"    =&gt; "Grape",
                                      "color"   =&gt; "green",
                                      "taste"   =&gt; "sweet",
                                      "healthy" =&gt; "yes"
                                )
              );
  </code></pre>
  
  <p>If I want to DISPLAY all green coloured fruit, I can do the following (let me know if this is the best way of doing it);</p>
  
  <pre><code>for ($row = 0; $row &lt; 3; $row++) {
  
      if($fruit[$row]["color"]=="green") {
  
           echo $fruit[$row]["name"] . '&lt;br /&gt;';
  
      }
  
  }
  </code></pre>
  
  <p>This will output;</p>
  
  <pre><code>Apple
  Grape
  </code></pre>
  
  <p>That's great and I can see their are 2 values there, but how can I actually get PHP to count the number of fruit where the colour is green and put it in a variable for me to use further down the script to work stuff out? E.g. I want to do something like;</p>
  
  <pre><code>if($number_of_green_fruit &gt; 1) { echo "You have more than 1 piece of green fruit"; }
  </code></pre>
  
  <p>I've taken a look at count(); but I don't see any way to add a 'WHERE/conditional' clause (a la SQL).</p>
  
  <p>Any help would be really appreciated.</p>