Here's the idea: a user enters his ZIP code.
Based on the inserted ZIP code, I get an array of ZIP codes (distance ordered).
Next I want to order an existing array of ZIP codes based on the distance ordered array.
So basically I have two arrays:
You could use
array_intersect() to get only the values of the second array that are also in the first array. And as the function preserves the keys - and so the order -, you only have to renumber them.
$a1=array(2018,2500); $a2=array(2000,2500,2050,2018); $a3=array_intersect( $a2 , $a1 ); echo print_r($a3,true);
Array (  => 2500  => 2018 )