Q:

Sorting an array in the same order as another array

I have two arrays that looks like this:
Array 1, $ids:
$ids = array('8', '56', '33', '23', ... and so on);

Array 2 (multidimensional as well as associative), $positions:
$positions[0] = array('id' => '56',
                 'latitude' => '45.34234',
                 'longitude' => '34.23942');

$positions[1] = array('id' => '8',
                 'latitude' => '49.34834',
                 'longitude' => '34.93942');

... and so on.

Both arrays contains of id's, but the id's aren't in the same order in the different arrays. What I want is the id's (with their latitudes and longitudes) to be in the same order in $positions as they're in $ids.
How can I do this?

A:

Try this code,
$new_positions = array();
foreach($ids as $k=>$v){
  foreach($positions as $k1=>$v1){
    if($v == $v1['id']){
       array_push($new_positions, $v1);
       continue;
    }
  }
}

$positions = $new_positions;
print_r($positions);

Check here, http://codepad.org/phWxOEC1

