title: Is there any memory limit for json_encode() method?
body: <p>I am trying to echo a json-encoded array which consist of an array but i dont know it is not letting me print that thing. Here's my code:</p>
  
  <pre><code>&lt;?php
  
  include_once('confi.php');
  header('Content-type: application/json');
  
  if ($_SERVER['REQUEST_METHOD'] == "POST")
  {
      $lastRecord = isset($_POST['lastRecordID']) ? 
                        mysql_real_escape_string($_POST['lastRecordID']) : "";
  
      $queryForTotalRec = mysql_query("SELECT customer_id FROM `WebServiceTesting`.`sapphire` ORDER BY customer_id DESC LIMIT 1");
      $total_rec = mysql_fetch_row($queryForTotalRec);
  
      if($total_rec){
          $queryForAllRecords = "SELECT * FROM `WebServiceTesting`.`sapphire` WHERE customer_ID BETWEEN %d AND %d";
         $get_all_recs = mysql_query(sprintf($queryForAllRecords, $lastRecord, $total_rec[0]));
  
          $json = array();
          while($row = mysql_fetch_assoc($get_all_recs)){
  
            $json[] = array("Status" =&gt; 1, "NewRecord" =&gt; $row);
          }
  
          print_r($json);
          echo json_encode($json);
     }else{
      $json = array("status" =&gt; 0, "Error_Message" =&gt; mysql_error());
            echo json_encode($json);
      }
  }else{
  
      $json = array("status" =&gt; 0, "Error_Message" =&gt; "Request Method not correct");
        echo json_encode($json);
  
  }
  @mysql_close($conn);
  </code></pre>
  
  <p>Errors:
  Malformed JSON: Unexpected 'A' sometimes 'I'</p>
  
  <p>When i am deleting the print_r line iam getting:
  No response received
  When i am printing the count of $json array iam getting a count of 153 but NO OTHER output.</p>
  
  <p>Things i've tried:</p>
  
  <p>i read in some solutions to similar problems that u need to use array_values()
  for e.g:</p>
  
  <pre><code> echo json_encode(array_values($json));
  </code></pre>
  
  <p>same response:  'No response received'</p>
  
  <p>I've also tried putting echo $json inside loop which I know that is conceptually wrong but still and got expected error 'Syntax error'</p>
  
  <p>Also, i tried echoing through foreach no luck Syntax error but i can see output in raw but cannot validate the json. </p>
  
  <p>Just for the info on print_r this is the response:</p>
  
  <pre><code>Array (
   [0] =&gt; Array ( 
       [Status] =&gt; 1 [NewRecord] =&gt; Array ( 
                     [customer_id] =&gt; 1241 
                     [firstName] =&gt; Katy 
                     [lastName] =&gt; Lest
                     [email] =&gt; klest@yahoo.com [phone] =&gt; 787012425
                                           )
                 )
   [1] =&gt; Array ( 
        [Status] =&gt; 1 [NewRecord] =&gt; Array ( 
                      [customer_id] =&gt; 1242 
                      [firstName] =&gt; Hanah 
                      [lastName] =&gt; Morrisn 
                      [email] =&gt; road@gmail.com
                      [phone] =&gt; 144221275  )
                )
   [2] =&gt; Array (
         [Status] =&gt; 1 [NewRecord] =&gt; Array ( 
                      [customer_id] =&gt; 1243 
                      [firstName] =&gt; James 
                      [lastName] =&gt; McGrath
                      [email] =&gt; rosamcgrath@hotmail.com
                      [phone] =&gt; 79684312  )
               ) 
  )
  </code></pre>
  
  <p>Just found a sort of answer to this i am still looking for a reason if anyone can help in that please. The number of Records i was pulling were 150+ so i just tried with 50 records at a time and it worked perfectly. Anyone know how can i actually allocate more memory to my array so that it can hold all the required data at once only ? </p>
  
  <p>I have also tried by giving accurate index as well i thought that array goes out of memory but this even not working:</p>
  
  <pre><code> $json = new SplFixedArray($difference);
  </code></pre>
  
  <p>Your assistance would be very much appreciated.</p>