No again;-)
The problem i have is that i have an array in an array in an array...
i see the folowing function ... but is only can handle 2 arrays:
Please discard my previous post[perhaps an admin can deleted it for me? :-)]. It turns out the original script I implemented it in didn't seem to work properly. After more development, I did find a method that works as theorized in my previous post. I also added in a new function. What it does is allows you to add in multiple key names, it will then sort them in that order, the purpose is, is that if the first one is the same throughout, it will jump to the next key.
Here's the script:
<?php
// +-- First let's set up the multidimensional array.
$array[0][username] = "user_name";
$array[0][password] = "pass_word";
$array[0][account_type] = "admin";
$array[1][username] = "eman_resu";
$array[1][password] = "drow_ssap";
$array[1][account_type] = "user";
$array[2][username] = "php_roxs";
$array[2][password] = "yesitdoes";
$array[2][account_type] = "admin";
// +-- Run it through the function.
$sorted = mu_sort($array, "password,account_type");
// +-- Print out the results[just for this test]
print_r($sorted);
// +-- Here's the function:
function mu_sort ($array, $key_sort) { // start function
$key_sorta = explode(",", $key_sort);
$keys = array_keys($array[0]);
// sets the $key_sort vars to the first
for($m=0; $m < count($key_sorta); $m++){ $nkeys[$m] = trim($key_sorta[$m]); }
$n += count($key_sorta); // counter used inside loop
// this loop is used for gathering the rest of the
// key's up and putting them into the $nkeys array
for($i=0; $i < count($keys); $i++){ // start loop
// quick check to see if key is already used.
if(!in_array($keys[$i], $key_sorta)){
// set the key into $nkeys array
$nkeys[$n] = $keys[$i];
// add 1 to the internal counter
$n += "1";
} // end if check
} // end loop
// this loop is used to group the first array [$array]
// into it's usual clumps
for($u=0;$u<count($array); $u++){ // start loop #1
// set array into var, for easier access.
$arr = $array[$u];
// this loop is used for setting all the new keys
// and values into the new order
for($s=0; $s<count($nkeys); $s++){
// set key from $nkeys into $k to be passed into multidimensional array
$k = $nkeys[$s];
// sets up new multidimensional array with new key ordering
$output[$u][$k] = $array[$u][$k];
} // end loop #2
} // end loop #1
// sort
sort($output);
// return sorted array
return $output;
} // end function
?>