-3

I have below 2 array values.

Array 1 - 2,1,3,0
Array 2 - 7,1,5,10.

Now i want 2 array like below.

Array 1 - 0,1,2,3
Array 2 - 10,1,7,5
dayana
  • 79
  • 1
  • 11
  • Have you tried anything? – Rizier123 Oct 16 '15 at 19:31
  • Did you take the site's [tour](http://stackoverflow.com/tour)? – al'ein Oct 16 '15 at 19:33
  • Yes i tried implode than from string... go through for each but it always give me just 10. – dayana Oct 16 '15 at 19:34
  • Read the full [Sorting Arrays](http://php.net/manual/en/array.sorting.php) document from PHP.net and best of luck with your attempts and research. Come back here when you have a code with an issue to show us so we can offer help with it. – al'ein Oct 16 '15 at 19:35
  • Even i also go through site. Pelase see below list. http://stackoverflow.com/questions/348410/sort-an-array-by-keys-based-on-another-array – dayana Oct 16 '15 at 19:35

1 Answers1

0

You could try sorting by value the first array, but maintain the index association. Then use the new order of keys to sort the other array:

asort($arr1);

$sorted_arr2 = [];
foreach($arr1 as $key=>$val) {
  array_push($sorted_arr2, $arr2[$key]);
}
fibono
  • 773
  • 2
  • 10
  • 23