Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting two corresponding arrays in PHP [duplicate]

I have two arrays, both have numbers but are extracted in specific order from a database. So what I want to do is to sort one of them in a acceding mode and the second array rearrange it's values to correspond the first one. for instance

$firstarray=array(14,30,20);
$secondarray=array(4,2,3);

So in our example I need the first array to become (14,20,30) witch can be made with the sort function but the second also have to become (4,3,2) to correspond with the first array.

Any ideas?

like image 316
Wimp6612 Avatar asked Jun 13 '26 09:06

Wimp6612


1 Answers

You can use array_combine to make one array and then sort it

like image 56
cornelb Avatar answered Jun 16 '26 17:06

cornelb