[ create a new paste ] login | about

Link: http://codepad.org/GMpf7pFt    [ raw code | output | fork ]

PHP, pasted on Jun 20:
<?

$array = array(
        'note' => array('test', 'test1', 'test2', 'test3', 'test4'),
        'year' => array('2011','2010', '2012', '2009', '2010'),
        'type' => array('conference', 'journal', 'conference', 'conference','conference'),
    );


// Storing the original keys
$original_keys = array_keys($array);

$temp_array = array();

// Restructuring the array for sorting
foreach($array as $items){
   $index = 0;
        foreach($items as $item){
            $temp_array[$index++][] = $item;
        }
}


array_multisort($array['type'], SORT_ASC, SORT_STRING, $array['year'], SORT_DESC, $temp_array);

// Restoring the temp array in original format
$array = array();
foreach($temp_array as $items){
    $index = 0;
    foreach($original_keys as $key){
       $array[$key][] = $items[$index++];
    }
}
print_r($array);


Output:
Array
(
    [note] => Array
        (
            [0] => test2
            [1] => test
            [2] => test4
            [3] => test3
            [4] => test1
        )

    [year] => Array
        (
            [0] => 2012
            [1] => 2011
            [2] => 2010
            [3] => 2009
            [4] => 2010
        )

    [type] => Array
        (
            [0] => conference
            [1] => conference
            [2] => conference
            [3] => conference
            [4] => journal
        )

)


Create a new paste based on this one


Comments: