I have created an array as the result of two mysql queries and what I need to do now is sort the array. I have done some searching around and I believe that I need to use the "array_multisort" function. I have managed to get this to work but what I need to be able to do is sort on multiple keys.
Here is some test code that I have been using:
<?php
$input_array = array(
0 => array('field_1' => 100, 'field_2' => 80, 'name' => 'Fred', 'field_3' => 2, 'field_4' => 'fred@domain.com'),
1 => array('field_1' => 100, 'field_2' => 80, 'name' => 'Bill', 'field_3' => 2, 'field_4' => 'bill@domain.com'),
2 => array('field_1' => 200, 'field_2' => 50, 'name' => 'John', 'field_3' => 6, 'field_4' => 'john@domain.com'),
3 => array('field_1' => 60, 'field_2' => 200, 'name' => 'Bill', 'field_3' => 11, 'field_4' => 'bill@domain.com'),
4 => array('field_1' => 100, 'field_2' => 80, 'name' => 'John', 'field_3' => 2, 'field_4' => 'john@domain.com') );
print_r($input_array);
foreach ($input_array as $val)
{
$sort_key[] = $val['name'];
}
array_multisort(($sort_key, SORT_ASC, SORT_REGULAR, $input_array);
print_r($input_array);
?>
What I want to do now is have the sort key as "name, field_2, field_3"
My question is "Can this be done?" and if so how - or should I be using some other function?