Sort an array with keys

Hi I want to sort and array by other array let me show you example.

Input array: 
$input_array = array(
  '51171#2'  => array(
     'download_id'  => 51171,
     'variation_id' => 2,
  ),
  '143516#2' => array(
     'download_id'  => 143516,
     'variation_id' => 2,
  ),
  '396346#2' => array(
     'download_id'  => 396346,
     'variation_id' => 2,
  ),
  '143516#1' => array(
     'download_id'  => 143516,
     'variation_id' => 1,
  ),
  '396344#2' => array(
     'download_id'  => 396344,
     'variation_id' => 2,
  ),
  '396346#1' => array(
     'download_id'  => 396346,
     'variation_id' => 1,
  ),
  '396344#1' => array(
     'download_id'  => 396344,
     'variation_id' => 1,
  ),
);

Sorting sequence: 
$order = array( 143516, 396344, 396346 );

Output sorted array should be like below: 
$result_array = array(
  '143516#2' => array(
     'download_id'  => 143516,
     'variation_id' => 2,
  ),
  '143516#1' => array(
     'download_id'  => 143516,
     'variation_id' => 1,
  ),
  '396344#2' => array(
     'download_id'  => 396344,
     'variation_id' => 2,
  ),
  '396344#1' => array(
     'download_id'  => 396344,
     'variation_id' => 1,
  ),
  '396346#2' => array(
     'download_id'  => 396346,
     'variation_id' => 2,
  ),
  '396346#1' => array(
     'download_id'  => 396346,
     'variation_id' => 1,
  ),
  '51171#2'  => array(
     'download_id'  => 51171,
     'variation_id' => 2,
  ),
);

I know it is bit tricky, but anyone help will be appreciated. Thanks