title: Datatables data from json_encode PHP array
body: <p>Their documentation ( datatables.net ) regarding this seems to be tucked inside some huge PHP tutorial. The one I found is here: <a href="http://datatables.net/development/server-side/php_mysql" rel="nofollow">http://datatables.net/development/server-side/php_mysql</a></p>
  
  <p>All I want to know, is how to make an array, using PHP which will later be hit with json_encode() with static data (no variables) to populate a table which has a few column titles and a few example rows of data. Some of this was taken from the tutorial above.</p>
  
  <pre><code>&lt;?php
      $output = array(
          "sEcho" =&gt; intval($_GET['sEcho']), //no idea what this is
          "iTotalRecords" =&gt; $iTotal, //probably total records
          "iTotalDisplayRecords" =&gt; $iFilteredTotal, //Not sure, records per page?
          "aaData" =&gt; array() //setting the data array for the rows
          );
      $output['aaData'][] = //each row here, unsure of format
  
      //Where do the column titles go, and the format for those?
  ?&gt;
  &lt;script type="text/javascript"&gt;
      $(document).ready(function() {
  
          var aDataSet = &lt;?php echo json_encode($output); ?&gt;
  
          $('#demo').html( '&lt;table cellpadding="0" cellspacing="0" border="0" class="display" id="example"&gt;&lt;/table&gt;' );
          $('#example').dataTable( {
              "aaData": aDataSet,
              "aoColumns": aoDataSet //This would be a second json_encode PHP array, set to var aoDataSet
          } ); 
      } );
  &lt;/script&gt;
  </code></pre>
  
  <p>Any help would be appreciated.</p>
  
  <p>EDIT: With some help from user2657979's answer, I have the answer to my question now. Below is the answer to populate DataTables title and data from PHP arrays.</p>
  
  <pre><code>&lt;?php
  $aoColumnDefs = array(
      array(
          'sTitle'   =&gt; 'Column 1',
          'aTargets' =&gt; array(0) 
      ),
      array(
          'sTitle'   =&gt; 'Column 2',
          'aTargets' =&gt; array(1) 
      ),
      array(
          'sTitle'   =&gt; 'Column 3',
          'aTargets' =&gt; array(2) 
      ),
      array(
          'sTitle'   =&gt; 'Column 4',
          'aTargets' =&gt; array(3) 
      ),
      array(
          'sTitle'   =&gt; 'Column 5',
          'aTargets' =&gt; array(4) 
      )
  );
  
  $aoRowDefs = array(
      0   =&gt;  array(
          0   =&gt;  "Row 1 data Column 1", 
          1   =&gt;  "Row 1 data Column 2",
          2   =&gt;  "Row 1 data Column 3",
          3   =&gt;  "Row 1 data Column 4",
          4   =&gt;  "Row 1 data Column 5"
          ),
      1   =&gt;  array(
          0   =&gt;  "Row 2 data Column 1",
          1   =&gt;  "Row 2 data Column 2",
          2   =&gt;  "Row 2 data Column 3",
          3   =&gt;  "Row 2 data Column 4",
          4   =&gt;  "Row 2 data Column 5"
          ),
      2   =&gt;  array(
          0   =&gt;  "Row 3 data Column 1",
          1   =&gt;  "Row 3 data Column 2",
          2   =&gt;  "Row 3 data Column 3",
          3   =&gt;  "Row 3 data Column 4",
          4   =&gt;  "Row 3 data Column 5"
          )
      );
  ?&gt;
  
  &lt;script type="text/javascript"&gt;
  
      var aoRowDefs = &lt;?php echo json_encode($aoRowDefs); ?&gt;
  
      var aoColumnDefs = &lt;?php echo json_encode($aoColumnDefs); ?&gt;
  
      $(document).ready(function() {
          $('#demo').html( '&lt;table cellpadding="0" cellspacing="0" border="0" class="display" id="example"&gt;&lt;/table&gt;' );
          $('#example').dataTable( {
          "aaData": aoRowDefs,
          "aoColumns": aoColumnDefs
          } ); 
      } );
  &lt;/script&gt;
  
  &lt;div id="demo"&gt;
      &lt;div id="example"&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>