title: Php rearrange array according to the key
body: <p>I tried convert the array type from $data to $data2 but didn't have success.</p>
  
  <p>In the <code>$data</code> array all values placed according to dates.</p>
  
  <p>But in the <code>$data2</code> values are placed according to the title.</p>
  
  <p>I wonder if it's convertable array.</p>
  
  <pre><code>$data['Group1']['Date1']['Empty'] = 5;
  $data['Group1']['Date1']['Reservated'] = 1;
  $data['Group1']['Date1']['WillReturn'] = 3;
  $data['Group1']['Date1']['Remains'] = 1;
  $data['Group1']['Date2']['Empty'] = 2;
  $data['Group1']['Date2']['Reservated'] = 2;
  $data['Group1']['Date2']['WillReturn'] = 3;
  $data['Group1']['Date2']['Remains'] = -3;
  
  $data['Group2']['Date1']['Empty'] = 0;
  $data['Group2']['Date1']['Reservated'] = 1;
  $data['Group2']['Date1']['WillReturn'] = 3;
  $data['Group2']['Date1']['Remains'] = -4;
  $data['Group2']['Date2']['Empty'] = 10;
  $data['Group2']['Date2']['Reservated'] = 1;
  $data['Group2']['Date2']['WillReturn'] = 1;
  $data['Group2']['Date2']['Remains'] = 8;
  
  $data2 = [
      'Group1' =&gt; [
          [ 'Title' =&gt; 'Empty',
              'Date1' =&gt; 5,
              'Date2' =&gt; 2,
  
          ],
          [ 'Title' =&gt; 'Reservated',
              'Date1' =&gt; 1,
              'Date2' =&gt; 2,
  
          ],
          [ 'Title' =&gt; 'WillReturn',
              'Date1' =&gt; 3,
              'Date2' =&gt; 3,
          ],
          [ 'Title' =&gt; 'Remains',
              'Date1' =&gt; 1,
              'Date2' =&gt; -3,
          ],
          // etc...
      ],
      'Group2' =&gt; [
          [ 'Title' =&gt; 'Empty',
              'Date1' =&gt; 0,
              'Date2' =&gt; 10,
  
          ],
          [ 'Title' =&gt; 'Reservated',
              'Date1' =&gt; 1,
              'Date2' =&gt; 1,
  
          ],
          [ 'Title' =&gt; 'WillReturn',
              'Date1' =&gt; 3,
              'Date2' =&gt; 1,
          ],
          [ 'Title' =&gt; 'Remains',
              'Date1' =&gt; -4,
              'Date2' =&gt; -8,
          ],
          // etc...
      ],
      // etc...
  ];
  </code></pre>
  
  <p>Some try here:</p>
  
  <pre><code>$new = [];
      $grp = array_keys($datax);
      $i =0;
      foreach($datax as $key =&gt; $val)
      {
          $dates = array_keys($val);
          foreach($val as $k=&gt;$v)
          {
              $cases = array_keys($v);
              $caseAndVals[$i]=$v;
              $i++;
          }
      }
      $z =0;
      $y = 0;
      foreach($grp as $g)
      {
          foreach($cases as $c)
          {
              $new[$g][$z]['Title']=$c;
              foreach($dates as $d)
              {
                  $new[$g][$z][$d] = 'values which correspond to the date and title';
              }
              $z++;
          }
  
      }
  </code></pre>
  
  <p>I converted array according to group and cases but i didn't have success to  place values corresponded dates...</p>