figured it out. It was complicated too, because I had to insert the array keys into the value between the numbers and the text as text and remove it after the array was sorted and the split arrays were spliced back together. I'll try to post the code a bit later. The code is short and not too complicated, but figuring out how to do it was.
Code:
$key[anderson]=12000045value;
$key[mike]=12000047reverse;
$key[tom]=21000047absent;
foreach ($key as $name => $row1){}
Code:
$new=array();$new1=array();$new2=array();$row3=array();
$count_n=count($name);$a=0;
while ($a<=$count_n)
{$new["$name[$a]"]=$row1[$a];
$a++;}
foreach ($new as $name1 => $row2)
{
$row3=substr("$row2",0,5);
$row2=substr("$row2",5);
$row2=substr_replace($row2,$name1,3,0);
$new["$name1"]=$row2;
$new1["$name1"]=$row3;
}
asort($new);
foreach($new as $name1 => $row2)
{$row2=str_replace("$name1","",$row2);$new["$name1"]="$new1[$name1]$row2";}
In the first foreach I separated $key into two arrays: one for the keys and one for the values.
In the while statement (which I'll probably change to a foreach since I no longer need to avoid certain parts of the array) I started a new array which is a duplicate of the original array.
In the second foreach statement I split the duplicate array $new, removed the first 5 characters of the value and inserted the key name into the value between the numbers and the text, and saved the 5 removed digits for later.
Next I sorted the array, which will now sort the array by value and then by key.
In the last foreach the key names are removed from the values where they were inserted and the first 5 numbers that were removed earlier are put back where they were thus returning the values to their original value.
I hope that wasn't too complicated. I am pretty sure that I can simplify it further, but the above code was the first working version I came up with. The above code is pretty close to what I am using, but with a few minor changes.
Bookmarks