3v4l.org

run code in 300+ PHP versions simultaneously
<?php $my_array = ['A1'=>'Data1','A2'=>'Data2','A3'=>'Data3','A4'=>'Data4','A5'=>'Data5']; $allowed = ['0'=>'A1','1'=>'A2','2'=>'A3']; $filtered = array_filter( $my_array, function ($key) use ($allowed) { return in_array($key, $allowed); }, ARRAY_FILTER_USE_KEY ); var_dump($filtered);

preferences:
129.45 ms | 406 KiB | 5 Q