Filtering array by list of keys in PHP 5.5
I always believe that you should use built in functions wherever possible, as opposed to recreating PHP functionality with loops etc. The main reasons for saying this are that:


We should trust that PHP functions achieve their desired result in an efficient manner, and:
If they are improved in future versions your code doesn't need to change, but just gets better.


That being said, why not something like this:

$matches = array_intersect_key($langs, array_flip($allowed_langs));
var_export($matches);