title: PHP Array Length always 5
body: <p>I am querying MS SQL Server and storing the results in a json array, then passing the results to Javascript.  My issue is that based off if a variable isset the array length SHOULD be either 4 or 5 length.  However, the array is ALWAYS showing a length of 5.</p>
  
  <p>This is the php that I am using.</p>
  
  <pre><code>&lt;?php
      $sql = "Select ";
      if (isset($_GET['namepull'])) {
          $sql .= "name,";
      }
      $sql .= " address, city, state, zip from employeefile";
      $db-&gt;setQuery($sql);
      $rows = $db-&gt;loadRowList();
      $output = array();
      foreach ($rows as $row) {
          array_push($output, $row);
      }
      echo $sql;
      $jsondata = json_encode($output[0]); 
  ?&gt;
  </code></pre>
  
  <p>Which to me the below query strings should show an array length of 
  4 = <code>Select address, city, state, zip from employeefile</code>
  5 = <code>Select name, address, city, state, zip from employeefile</code></p>
  
  <p>Now the issue that I have is when it hits the below <code>&lt;script&gt;</code> a length of 5 is always produced, regardless of the query.  How should I modify the <code>&lt;script&gt;</code> so that an accurate count is returned?</p>
  
  <pre><code>&lt;script&gt;
      var arrayfromphp = &lt;?php echo $jsondata;  ?&gt;;
      alert (arrayfromphp.length);
  &lt;/script&gt;
  </code></pre>
  
  <p>If I perform a <code>console.log(arrayfromphp)</code> the last element when the count should be 4 is always <code>undefined x 1</code></p>
  
  <p><strong>Edit</strong><br>
  If I use <code>var_dump</code> below is the output I get (which is what I expect)</p>
  
  <pre><code>Array ( [0] =&gt; XXXXXXXXX [1] =&gt; New York [2] =&gt; New York [3] =&gt; 33333 )
  Array ( [0] =&gt; Jackie [1] =&gt; XXXXXXXXX [2] =&gt; New York [3] =&gt; New York [4] =&gt; 33333 )
  </code></pre>
  
  <p><strong>Edit Again</strong><br>
  It appears the issue is stemming from how I am populating a Javascript array from the php array.  See edit below with notes above lines</p>
  
  <pre><code>var arrayfromphp = &lt;?php echo $jsondata; ?&gt;;
  //Shows accurate count of 4
  console.log(arrayfromphp);
  
  var values = [];
  if (arrayfromphp.length = 5) {
      for (var i = 1; i &lt; arrayfromphp.length; i++) {
          values.push(arrayfromphp[i]);
      }
  } else if (arrayfromphp.length = 4) {
      for (var i = 0; i &lt; arrayfromphp.length; i++) {
          values.push(arrayfromphp[i]);
      }
  }
  //Shows 5
  alert(arrayfromphp.length);
  //Shows 5 with undefined x 1
  console.log(arrayfromphp);
  </code></pre>