title: PHP: Sort array according to another array of different length
body: <p>I have two arrays of different length:</p>
  
  <pre><code>$paths_table = array("TS-0007_a.jpg", "TS-0040_a.JPG", "TS-0040_b.JPG", "TS-0040_f.JPG", "TS-0041_a.JPG", "TS-0041_b.JPG");
  
  $order_table = array("TS-0040","TS-0007","TS-0041");
  </code></pre>
  
  <p>and I want to sort the first one using the second so that the output will be the array</p>
  
  <pre><code>$final_table = array("TS-0040_a.JPG", "TS-0040_b.JPG", "TS-0040_f.JPG", "TS-0007_a.jpg", TS-0041_a.JPG", "TS-0041_b.JPG")
  </code></pre>
  
  <p>Assuming that I'm going to use</p>
  
  <pre><code>strpos($paths_table[$i], $order_table[$j]);
  </code></pre>
  
  <p>to check if the string of $order_table is included in any of the $paths_table.</p>
  
  <p>How can I accomplish this?</p>