title: How to return array as multi dimensional array?
body: <p>I i'm developing php application. I have used Google Chart API for display charts.
  I have select and returned necessary data for chart.
  I got following array as my output.</p>
  
  <pre><code> print_r($output);
  
      //Out put
  
      Array
      (
      [0] =&gt; Array
          (
              [month] =&gt; April
              [sec_id] =&gt; 2
              [sec_name] =&gt; Commerce
              [count] =&gt; 1
          )
  
      [1] =&gt; Array
          (
              [month] =&gt; June
              [sec_id] =&gt; 2
              [sec_name] =&gt; Commerce
              [count] =&gt; 3
          )
  
      [2] =&gt; Array
          (
              [month] =&gt; July
              [sec_id] =&gt; 2
              [sec_name] =&gt; Commerce
              [count] =&gt; 1
          )
  
      [3] =&gt; Array
          (
              [month] =&gt; August
              [sec_id] =&gt; 4
              [sec_name] =&gt; Science
              [count] =&gt; 3
          )
  
      [4] =&gt; Array
          (
              [month] =&gt; August
              [sec_id] =&gt; 3
              [sec_name] =&gt; Maths
              [count] =&gt; 2
          )
  
      [5] =&gt; Array
          (
              [month] =&gt; August
              [sec_id] =&gt; 1
              [sec_name] =&gt; Art
              [count] =&gt; 2
          )
  
      [6] =&gt; Array
          (
              [month] =&gt; August
              [sec_id] =&gt; 2
              [sec_name] =&gt; Commerce
              [count] =&gt; 2
          )
  
  )
  
  
      print_r(json_encode($output)); // return above array as output
  </code></pre>
  
  <p>I request above data using ajax ( data type is JSON)
  <strong>I want to return data as bellow</strong> to generate google chart.</p>
  
  <pre><code>[
  ['Month', 'Art', 'Commerce', 'Maths', 'Sience'],
  ['April',  '', 2, '', ''],
  ['June',  '', 3, '', ''],
  ['July',  '', 1, '', ''],
  ['August',  2, 2, 3, 3]
   ]
  </code></pre>
  
  <p><strong>I tried this this code</strong></p>
  
  <pre><code>$output = array();
  $output[0] = array('Month', 'Art', 'Commerce', 'Maths', 'Science');
  
  foreach($records as $key=&gt; $record){
      $art =''; $commerce =''; $maths=''; $science='';
      if($record['sec_id'] == 1){
          $art = $record['count'];
      }else if($record['sec_id'] == 2){
          $commerce = $record['count'];
      }else if($record['sec_id'] == 3){
          $maths = $record['count'];
      }else if($record['sec_id'] == 4){
          $science = $record['count'];
      }
  
      $output[++$key] = array(0 =&gt; $record['month'], 1 =&gt; $art, 2 =&gt; $commerce, 3 =&gt; $maths, 4 =&gt; $science);
  }
  
  function super_unique($array){
    $result = array_map("unserialize", array_unique(array_map("serialize", $array)));
  
    foreach ($result as $key =&gt; $value){
      if ( is_array($value)){
        $result[$key] = super_unique($value);
      }
    }
      return $result;
  }
  
  
  $output = super_unique($output);
  </code></pre>
  
  <p><strong>Out put was</strong></p>
  
  <pre><code>[["Month","Art","Commerce","Maths","Science"],["April","","1"],["June","","3"],["July","","1"],{"0":"August","1":"","4":"3"},{"0":"August","1":"","3":"2"},["August","2",""],["August","","2"]]
  </code></pre>