php1 Posted September 29, 2008 Share Posted September 29, 2008 dear all, I have a usort function to sort an array based on one value in the array usort($split1, 'callback'); print_r($split1); function callback($a, $b) { if ($a[$key] == $b[$key]) return 0; return $a[3] > $b[3] ? 1 : -1; } my $split1 is given below: Array ( [0] => Array ( [0] => 22-08-2008 [1] => 18:12:20 [2] => 101 [3] => 120 ) [1] => Array ( [0] => 22-08-2008 [1] => 20:01:15 [2] => 190 [3] => 120 ) [2] => Array ( [0] => 22-08-2008 [1] => 20:01:15 [2] => 190 [3] => 220 ) ) here sorting works fine $split1[0][3]=$split1[1][3]= 120 . so each time i print the $split1 i got the $split[0] and $split[1] interchanged. is there any way to keep the array index same if the values are identical Link to comment https://forums.phpfreaks.com/topic/126258-problem-with-usort/ Share on other sites More sharing options...
sasa Posted September 29, 2008 Share Posted September 29, 2008 but $split1[0] != $split1[1] which of this two elements want to remove from array Link to comment https://forums.phpfreaks.com/topic/126258-problem-with-usort/#findComment-652909 Share on other sites More sharing options...
php1 Posted September 30, 2008 Author Share Posted September 30, 2008 I am displaying each of this values in a table. so my table row1 = 22-08-2008,18:12:20,101,120 table row2 = 22-08-2008,20:01:15,190,120 table row3 = 22-08-2008,20:01:15,190,220 i got the table like the above for the ffirst time. if i click refresh then my row became table row1 = 22-08-2008,20:01:15,190,120 table row2 = 22-08-2008,18:12:20,101,120 table row3 = 22-08-2008,20:01:15,190,220 ie table row1 and table row2 got interchanged. is there any way to keep the table row1 as it is using usort Link to comment https://forums.phpfreaks.com/topic/126258-problem-with-usort/#findComment-653596 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.