Can someone explain this piece of php code to me
<p>I understand the first half but am struggling with the second half. In particular the line "(key($a) !== $i)" is where I stop understanding. It is saying that if the key of the array $a is not equal to the index counter $i then the boolean vairable $isList is assigned false but I don't understand the signifigance of this statement. What does key($a) !== $i tell us usefully about the array $a? The lines following that statement also elude me. Please explain to me? Thank you</p>

<pre><code>function getJsCode($a) {
if (is_null($a)) return 'null';
if ($a === false) return 'false';
if ($a === true) return 'true';
if (is_scalar($a)) {
    $a = addslashes($a);
    $a = str_replace("\n", '\n', $a);
    $a = str_replace("\r", '\r', $a);
    return "'".$a."'";
}

$isList = true;
for ($i=0, reset($a); $i&lt;count($a); $i++, next($a))
    if (key($a) !== $i) { $isList = false; break; }
$result = array();
if ($isList) {
    foreach ($a as $v) $result[] = getJsCode($v);
    return '[ ' . join(',', $result) . ' ]';
} else {
    foreach ($a as $k=&gt;$v) $result[] = getJsCode($k) . ': ' . getJsCode($v);
    foreach ($a as $k=&gt;$v) $result[] = $k . ': ' . getJsCode($v);
    return '{ ' . join(', ', $result) . ' }';
}
}
</code></pre>
