What I'm trying to do is preserve the order of an array, while determining if each of the numbers match numbers that were pulled from the database. What I have is an array of numbers ($ids), and a non empty array of rows ($rows)
$images = array();
$ids = array(
    0    => '41',
    1  => '42',
    2  => '43',
    3 => '44'
);
// database example
$rows = array(
    0 => array(
        'name' => 'John Doe',
        'id' => '42'
    ),
    1 => array(
        'name' => 'Jane Doe',
        'id' => '43'
    ),
);
$i = 0;
foreach ($rows as $row) {
   // This works, but it doesn't preserve the order of the $ids array
   if (in_array($row['id'], $ids[$i])) {
      // add $id to a new array
      // or use the same $id array
      $images[$i]['name'] = $row['name'];
      $images[$i]['id'] = $row['id'];
      $i++;
   }
}
Any help would be appreciated.