I have this array:
  $routes = array(
  array(
     'code' => 'PZSA',
     'name' => 'PLaza san antonio',
  ),
  array(
     'code' => 'AVAD',
     'name' => 'Av de asturias',
  ),
  array(
     'code' => 'AVAR',
     'name' => 'Av simon nieto',
  )
  );
And I want to sort it based on the next keys:
$target = array('AVAD', 'AVAR', 'PZSA');
So the sorted array will be:
Array
(
[0] => Array
    (
        [code] => AVAD
        [name] => Av de asturias
    )
[1] => Array
    (
        [code] => AVAR
        [name] => Av simon nieto
    )
[2] => Array
    (
        [code] => PZSA
        [name] => PLaza san antonio
    )
)
I've tried this and it works, but I think is too much code for this simple thing. Any alternatives? Thanks.
  function _sort($array, $orderArray) {
      $ordered = array();
      foreach ($orderArray as $key) {
        $ordered[] = find($key, $array);
      }
      return $ordered;
   }
   function find($code, $routes) {
      foreach ($routes as $key => $value) {
         if ($routes[$key]['code'] == $code) {
            return $routes[$key];
         }
      }
   }
$sorted = _sort($routes, $target);