convert portion of code into a function php
<p>This is probably very easy to do but for some reason I can't seem to figure this out. Let's say I have code like this:</p>

<pre><code>$elements = array('a', 'b', 'c', 'd');

$myValues = array(
    'values' =&gt; array(
        'a' =&gt; array(
            'xx' =&gt; 3,
            'yy' =&gt; ''
        ),
        'b' =&gt; array(
            'xx' =&gt; '',
            'yy' =&gt; ''
        ),
        'c' =&gt; array(
            'xx' =&gt; 8.4,
            'yy' =&gt; ''
        ),
        'd' =&gt; array(
            'xx' =&gt; 18.4,
            'yy' =&gt; ''
            )
        )
);

foreach($elements as $elem)
{
    if($myValues['values'][$elem]['xx'] != '')
    {
        if($myValues['values'][$elem]['xx'] &lt; 6)
        {
            $myValues['values'][$elem]['yy'] =  'less than 6';
        }
        elseif($myValues['values'][$elem]['xx'] &gt;= 6 &amp;&amp; $myValues['values'][$elem]['xx'] &lt; 15)
        {
            $myValues['values'][$elem]['yy'] =  'between 6 and 16';
        }
        else
        {
            $myValues['values'][$elem]['yy'] = 'greater than 15';
        }

            testFunc($myValues['values'][$elem]['xx']); // This is how I would call my function once I replace the code above
    }
}
</code></pre>

<p>As you can see here what I'm trying to do is to change the value of <code>$myValues['values'][$elem]['yy']</code> based on some conditions. What I want to do is to replace the <code>if elseif else</code> section of codes by a function that performs the same action.</p>

<p>I tried something like:</p>

<pre><code>function testFunc($xx)
{
    if($xx &lt; 6)
    {
        $yy = 'less than 6';
    }
    elseif($xx &gt;= 6 &amp;&amp; $xx &lt; 15)
    {
        $yy =  'between 6 and 16';
    }
    else
    {
        $yy = 'greater than 15';
    }

    return $yy;
}
</code></pre>

<p>But obviously this won't work because I'm not changing the value of <code>$myValues['values'][$elem]['yy']</code> inside my function. </p>

<p><strong>NOTE</strong> I really want to pass ONLY the value of <code>$myValues['values'][$elem]['xx']</code> inside my function and return the changed value of <code>$myValues['values'][$elem]['yy']</code>.</p>

<p>Can anybody help me with this?</p>

<p>Thanks in advance</p>
