I am trying do do a multidimensional array sort but it isn't working. This is my code. I want it sort
all the $TempItems[$i][0]'s then the $TempItems[$i][2]'s within that
while (!feof($files)) {
$record = fgets($files);
$record = trim(substr($record,1));
$record = substr($record,0,strlen($record) - 1);
$Items = split('","',$record);
if (trim($Items[2]) == "0") {
$i++;
$TempItems[$i][0] = trim($Items[0]);
$TempItems[$i][1] = trim($Items[1]);
$TempItems[$i][2] = trim($Items[3]);
}
}
print_r($TempItems);
echo "<br>";
echo "<br>";
array_multisort(
$TempItems[0], SORT_ASC,
$TempItems[2], SORT_NUMERIC, SORT_ASC
);
print_r($TempItems);
The first print_r gives
Array ( [0] => Array ( [0] => 23699923 [1] => http://images.portalimages.com/large/tp ... 530449.jpg [2] => 0 ) [1] => Array ( [0] => 23699923 [1] => http://images.portalimages.com/large/tp ... 530449.jpg [2] => 1 ) [2] => Array ( [0] => 23699923 [1] => http://images.portalimages.com/large/tp ... 530449.jpg [2] => 2 ) etc
After the sort I get
Array ( [0] => Array ( [0] => 0 [1] => 23699923 [2] => http://images.portalimages.com/large/tp ... 530449.jpg ) [1] => Array ( [0] => 23699923 [1] => http://images.portalimages.com/large/tp ... 530449.jpg [2] => 1 ) [2] => Array ( [0] => 2 [1] => 23699923 [2] => http://images.portalimages.com/large/tp ... 530449.jpg ) etc
Records 0 and 2 are wrong
It ends up as
Array ( [0] => Array ( [0] => 0 [1] => 23699923 [2] => http://images.portalimages.com/large/tp ... 530449.jpg ) etc
instead of
Array ( [0] => Array ( [0] => 23699923 etc
Why? The code looks ok to me but I presume I am confused somewhere. I know it starts off in the right order but I gatherr the input might always do
Thanks

