Reputation: 662
I have an array which i would like to sort it based on values from another one. FIrst array:
$array1 = ( '2' , [val]->'3' , [val1]->'1')
And second one:
$array2 = (1,4,3)
I've tried a bubble sort but does not work:
for ($i = 1 ; $i <= $array1[0] ; $i++){
for ($j = $i+1 ; $j <= $array1[0] ; $j++){
if ($array2[$i] < $array2[$j]){
$temp = $array1[$i];
$array1[$i] = $array1[$j];
$array1[$j] = $temp;
}
}
}
Upvotes: 1
Views: 166
Reputation: 11264
use usort()
, it allowes you to give user defined function to sort..
Upvotes: 1