Searching in PHP Nested Arrays
<p>I've been digging in and learning as much as I can about PHP Arrays, but have hit a stumbling block that I cannot figure out.</p>

<p>In my example code, I have an array that looks like this:</p>

<pre><code>$array = array("fruit" =&gt; array("apple", "orange", "pear"), "veg" =&gt; array("carrot","celery"));
</code></pre>

<p>Now, elsewhere in the code, I have a variable called $myfavouriteitem</p>

<pre><code>$myfavouriteitem = "apple";
</code></pre>

<p>With the value of the <code>$myfavouriteitem</code> variable, I'd like to return the value <code>"fruit"</code>. </p>

<p>I've tried using <code>array_search()</code> function in PHP, but I'm not having luck. I was able to use <code>array_search()</code> until the point where I introduced the nested array.</p>

<p>If I'm approaching this from the wrong angle, please let me know. My initial thought on this was to use a database to store this information (especially since I'm new to arrays); however, that's out of the question for this particular project. With that in mind, my data sets will all have a one-to-many relationship (one key with multiple values).</p>
