title: How to encode JSON in php
body: <p>I am getting some data from mysql server using php and encoding it into json.</p>
  
  <p>This is what i have so far:</p>
  
  <pre><code>[
      {
          "ImageID": "1",
          "ImageName": "Hakuna Matata",
          "Details": "some text"
      },
      {
          "ImageID": "2",
          "ImageName": "Hakuna Matata2",
          "Details": "some text"
      }
  ]
  </code></pre>
  
  <p>I would like to add an array in "details" but i dont know how to achieve this. Like in this format:</p>
  
  <pre><code>[
      {
          "ImageID": "1",
          "ImageName": "Hakuna Matata",
          "Details": ["some text","some text"]
      },
      {
          "ImageID": "2",
          "ImageName": "Hakuna Matata2",
          "Details": ["some text","some text"]
      }
  ]
  </code></pre>
  
  <p>I am new to dealing with php so please be gentle :)</p>
  
  <p>Here is my php file:</p>
  
  <pre><code>&lt;?php
  $objConnect = mysql_connect("localhost","root","1234");
  $objDB = mysql_select_db("weHappening");
  
  $strSQL = "SELECT * FROM all_events WHERE 1  ";
  $objQuery = mysql_query($strSQL);
  $intNumField = mysql_num_fields($objQuery);
  
  $resultArray = array();
  
  while($obResult = mysql_fetch_array($objQuery))
  
  {
  
  $arrCol = array();
  
  for($i=0;$i&lt;$intNumField;$i++)
  
  {
  
  $arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
  
  }
  
  array_push($resultArray,$arrCol);
  
  }
  
  mysql_close($objConnect);
  
  if (json_last_error() ===
  JSON_ERROR_NONE){
  //do something
  
  echo json_encode($resultArray);
  
  } else {
  //error its not json
  }
  
  ?&gt;
  </code></pre>