title: sort multidimension array by its keys and then by its value
body: <p>I want to sort two dimension array but its keys and its values.
  Array is like this</p>
  
  <pre><code>    Array
  (
      [0] =&gt; Array
          (
              [Transport] =&gt; imagem3.png
          )
  
      [1] =&gt; Array
          (
              [Transport] =&gt; imagem2.png
          )
  
      [2] =&gt; Array
          (
              [Transport] =&gt; imagem1.png
          )
  
      [3] =&gt; Array
          (
              [First] =&gt; dscn2439.jpg
          )
  
      [4] =&gt; Array
          (
              [First] =&gt; dscn2454.jpg
          )
  
      [5] =&gt; Array
          (
              [First] =&gt; 06052010282.jpg
          )
  
      [6] =&gt; Array
          (
              [First] =&gt; dscn2357.jpg
          )
  
      [7] =&gt; Array
          (
              [Manufacture] =&gt; 120140220_191807.jpg
          )
  
      [8] =&gt; Array
          (
              [Manufacture] =&gt; 20140220_191429.jpg
          )
  )
  </code></pre>
  
  <p>I have sorted array of array by its keys but what I want to do is I want to array like this</p>
  
  <pre><code>&lt;?php Array
  (
  [0] =&gt; Array
      (
          [Transport] =&gt; imagem1.png
      )
  
  [1] =&gt; Array
      (
          [Transport] =&gt; imagem2.png
      )
  
  [2] =&gt; Array
      (
          [Transport] =&gt; imagem3.png
      )
  
  [3] =&gt; Array
      (
         [First] =&gt; dscn2357.jpg
      )
  
  [4] =&gt; Array
      (
          [First] =&gt; dscn2439.jpg
      )
  
  [5] =&gt; Array
      (
           [First] =&gt; dscn2454.jpg
      )
  
  [6] =&gt; Array
      (
         [First] =&gt; 06052010282.jpg
      )
  
  [7] =&gt; Array
      (
          [Manufacture] =&gt; 120140220_191807.jpg
      )
  
  [8] =&gt; Array
      (
          [Manufacture] =&gt; 20140220_191429.jpg
      )
   )
   ?&gt;
  </code></pre>
  
  <p>I have sorted by its keys I am not able to sort by value please help what I have to do</p>
  
  <pre><code>function getListPortfolio($params){
  
          $dir ='./images/portfolio/';
          // Open a directory, and read its contents
          $folderArray=array();
          $fileArray=array();
          $extArray=array('.jpg', '.jpeg', '.png', '.gif');
          if (is_dir($dir)){
            if ($dh = opendir($dir)){
              while (($subdir = readdir($dh)) !== false){             
                  if(is_dir($dir.$subdir)){
                      if(!($subdir=='.' || $subdir=='..')){
                           $folderArray[]=$subdir;
                      }
                  }
              }
  
              arsort($folderArray);
              foreach($folderArray as $key=&gt;$value){
                  if($dhSub = opendir($dir.$value)){
                       while (($files = readdir($dhSub)) !== false){
                          $fileExists=$dir.$value.'/'.$files;
                          if(exif_imagetype($fileExists)){
                              if(is_file($fileExists)){
                                  $fileArray[][$value]=$files;                                        
                              }
                          }
                       }
                  }
              }
              closedir($dh);
            }
          }
          return $fileArray;
      }
  </code></pre>
  
  <p>I want dir in key and files in value.</p>
  
  <p>Solve:</p>
  
  <pre><code>function getListPortfolio($params){
  
          $dir ='./images/portfolio/';
          // Open a directory, and read its contents
          $folderArray=array();
          $fileArray=array();
          $data=array();
          $extArray=array('.jpg', '.jpeg', '.png', '.gif');
          if (is_dir($dir)){
            if ($dh = opendir($dir)){
              while (($subdir = readdir($dh)) !== false){             
                  if(is_dir($dir.$subdir)){
                      if(!($subdir=='.' || $subdir=='..')){
                           $folderArray[]=$subdir;
                      }
                  }
              }
  
              arsort($folderArray);
              foreach($folderArray as $key=&gt;$value){
                  if($dhSub = opendir($dir.$value)){
                       while (($files = readdir($dhSub)) !== false){
                          $fileExists=$dir.$value.'/'.$files;
                          if(exif_imagetype($fileExists)){
                              if(is_file($fileExists)){
                                  $fileArray[]=$files;                                        
                              }
                          }
                       }
                       asort($fileArray);
                       foreach($fileArray as $index=&gt;$filename){
                           $data[][$value]=$filename;
                       }
  
                  }
              }
              closedir($dh);
            }
          }
          return $fileArray;
      }
  </code></pre>
  
  <p>Array will look like this and i want to sort array [transport]=><strong>imagem2.jpg</strong> ' value not [0] this index.</p>
  
  <pre><code>Array
  ( [0] =&gt; Array ( [Transport] =&gt; imagem1.png )
  
  [1] =&gt; Array
      (
          [Transport] =&gt; imagem2.png
      )
  
  [2] =&gt; Array
      (
          [Transport] =&gt; imagem3.png
      )
  
  [3] =&gt; Array
      (
         [First] =&gt; dscn2357.jpg
      )
  
  [4] =&gt; Array
      (
          [First] =&gt; dscn2439.jpg
      )
  
  [5] =&gt; Array
      (
           [First] =&gt; dscn2454.jpg
      )
  )
  </code></pre>