How do I return a value from a PHP multi-dimensional array using a variable key?
<p>I am having trouble returning a value from a multidimensional array using a key ONLY when I externalize to create a function.</p>

<p>To be specific, the following code will work when inline in a page:</p>

<pre><code>&lt;?php 
foreach ($uiStringArray as $key) {
  $keyVal = $key['uid'];        
  if($keyVal == 'global001') echo $key['uiString'];
}
?&gt;
</code></pre>

<p>However, if I externalize the code as a function, like so:</p>

<pre><code>function getUIString($myKey) {
   // step through the string array and find the key that matches the uid, 
   // then return uiString

   $myString = "-1";

   foreach ($uiStringArray as $key) {
      $keyVal = $key['uid'];

      if($keyVal == 'global001') { 
         $myString = $key['uiString'];

      }

   }

   return $myString;

}
</code></pre>

<p>And then call it like this:</p>

<pre><code>&lt;?php getUIString('global001'); ?&gt;
</code></pre>

<p>It always returns -1, and will do so even if I use an explicit key in the function rather than a variable.  I can't understand why this works inline, but fails as a function.</p>

<p>I'm a relative PHP noob, so please forgive me if this includes a glaring error on my part, but I've searched all over for discussion of this behavior and found none.  </p>

<p>All help appreciated.</p>
