Sorting Multidimensional Arrays : Multidimensional Array « Data Structure « PHP






Sorting Multidimensional Arrays

 
<?php 
$data = array( 
    array('country'=>'Spain', 'language'=>'Spanish', 'visitors'=>1289), 
    array('country'=>'France', 'language'=>'French', 'visitors'=>984), 
    array('country'=>'Argentina', 'language'=>'Spanish', 'visitors'=>812)
); 

printf("<pre>%s</pre>\n", var_export($data, TRUE)); 

$cols = array(); 

foreach($data as $row) { 
    foreach($row as $key => $value) { 
        if( !isset($cols[$key]) ) 
            $cols[$key] = array(); 
        $cols[$key][] = $value; 
    } 
} 
$data = $cols; 

array_multisort($data['language'], $data['country'], $data['visitors']); 

printf("<pre>%s</pre>\n", var_export($data, TRUE)); 
?>
  
  








Related examples in the same category

1.Reference element in multidimensional Arrays
2.Defining a Multidimensional Array
3.Looping Through a Multidimensional Array
4.Displaying a Multidimensional Array using For each
5.Accessing multidimensional array elements
6.Creating Multidimensional Arrays
7.Creating a Multidimensional Array
8.Multidimensional array element value interpolation
9.Displaying Multidimensional Arrays
10.Displaying a multidimensional array
11.Find the Maximum Value in a Multidimensional Array
12.Generating fixed-width field data records without
13.Manipulating multidimensional arrays