Why this PHP function "forgets" parameters?
<p>I've fount this implementation of a function to convert an array to a URL. It seems correct and, in fact, it works pretty well in many cases, except when I pass an array value with a 0 value. This is the function:</p>

<pre><code>function strtourl($arr, $entity = true, $prefix = '') {
    $params = array();
    foreach ($arr as $k =&gt; $v)
        if ($v) {
            $params[] = is_array($v) ? strtourl($v, $entity, $prefix ? $prefix.'['.$k.']' : $k) :
                        sprintf($prefix ? $prefix.'[%s]' : '%s', urlencode($k)).'='.urlencode($v);
        }
    return implode($entity ? '&amp;amp;' : '&amp;', $params);
}
</code></pre>

<p>This is an example I'm using:</p>

<pre><code>$array = array(
    'type' =&gt; 0,
    'content' =&gt; array(
        'msg_id'    =&gt; 'XSS120',
        'source'    =&gt; 0,
        'dest'      =&gt; 4,
        'type'      =&gt; 0,
        'msg'       =&gt; 'message'
    )
);
</code></pre>

<p>It returns this string:</p>

<pre><code>content[msg_id]=XSS120&amp;content[dest]=4&amp;content[msg]=message
</code></pre>

<p>instead of this:</p>

<pre><code>type=0&amp;content[msg_id]=XSS120&amp;content[source]=0&amp;content[dest]=4&amp;content[type]=0&amp;content[msg]=message
</code></pre>

<p>What's happening and how to fix it?</p>
