title: Manually build JSON encodable array in PHP
body: <p>This is kind of a strange one.  I have a CSV that I'm uploading and passing to a PHP script that parses it into arrays, encodes it into a JSON string and sends it back to be further processed by my Javascript.  However, I am having difficulty getting the response in a format that is easily parsed.  Maybe it can be parsed, I'm just not sure how to access the data within.  </p>
  
  <p>PHP script for handling and parsing the CSV:</p>
  
  <pre><code>&lt;?php
   $file = $_FILES['file'];
   $tmp = $file['tmp_name'];
   $row = 1;
   $json = array();
   if(($handle = fopen($tmp, 'r')) !== false){
    while(($data = fgetcsv($handle, 10000, '\n')) !== false){
     $num = count($data);
     $row++;
  
     for($i = 0; $i &lt; $num; $i++){
      $values = split(',', $data[$i]);
  
      $value = array(
       sName =&gt; $values[0],
       sNick =&gt; $values[1],
       sEmail =&gt; $values[2],
       sSSOID =&gt; $values[3],
       sPwd =&gt; $values[4],
       sConfPwd =&gt; $values[5],
       sDescr =&gt; $values[6]
      );
  
      array_push($json, $value);
     }
     print_r(json_encode($json));
    }
    fclose($handle);
   }
  ?&gt;
  </code></pre>
  
  <p>The output ends up being an iterative response where the first array contains the first row of the CSV and the second array contains the first and second rows (the third array contains the first, second, and third, etc. etc.).  The very last array is the response that I want.  It is a well-formed JSON string; I am just unsure of how to get only that response.</p>
  
  <p>Sample response:</p>
  
  <pre><code>  [{"sName":"John Doe","sNick":"John","sEmail":"jdoe@email.com","sSSOID":"jdoe","sPwd":"Admin1234","sConfPwd":"Admin1234","sDescr":"Likes cats"}][{"sName":"John Doe","sNick":"John","sEmail":"jdoe@email.com","sSSOID":"jdoe","sPwd":"Admin1234","sConfPwd":"Admin1234","sDescr":"Likes cats"},{"sName":"Bill Frank","sNick":"Bill","sEmail":"bfrank@email.com","sSSOID":"bfrank","sPwd":"Admin1234","sConfPwd":"Admin1234","sDescr":"Likes dogs"}][{"sName":"John Doe","sNick":"John","sEmail":"jdoe@email.com","sSSOID":"jdoe","sPwd":"Admin1234","sConfPwd":"Admin1234","sDescr":"Likes cats"},{"sName":"Bill Frank","sNick":"Bill","sEmail":"bfrank@gmail.com","sSSOID":"bfrank","sPwd":"Admin1234","sConfPwd":"Admin1234","sDescr":"Likes dogs"},{"sName":"Sam Smith","sNick":"Sam","sEmail":"ssmith@email.com","sSSOID":"ssmith","sPwd":"Admin1234","sConfPwd":"Admin1234","sDescr":"Likes music"}]
  </code></pre>
  
  <p>The only response I need is the final array:</p>
  
  <pre><code>[{"sName":"John Doe","sNick":"John","sEmail":"jdoe@email.com","sSSOID":"jdoe","sPwd":"Admin1234","sConfPwd":"Admin1234","sDescr":"Likes cats"},{"sName":"Bill Frank","sNick":"Bill","sEmail":"bfrank@email.com","sSSOID":"bfrank","sPwd":"Admin1234","sConfPwd":"Admin1234","sDescr":"Likes dogs"},{"sName":"Sam Smith","sNick":"Sam","sEmail":"ssmith@email.com","sSSOID":"ssmith","sPwd":"Admin1234","sConfPwd":"Admin1234","sDescr":"Likes music"}]
  </code></pre>