1

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;  
        }
    }
}
2

1 Answer 1

1

use usort(), it allowes you to give user defined function to sort..

Documentation..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.