3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $mediaarray = array( array( 'file_type_id'=>'first file', 'other_stuff'=>'first other' ), array( 'file_type_id'=>'second file', 'other_stuff'=>'second other' ) ); $mediafiletype = array( array( 'id'=>'blabla', 'base_url'=>'first_url' ), array( 'id'=>'second file', 'base_url'=>'second_url' ) ); $baseUrlKeyMediaArray = array(); $NotbaseUrlKeyMediaArray = array(); foreach ($mediaarray as $key => $mavalue) { $match = false; foreach ($mediafiletype as $mftvalue) { if ($mavalue['file_type_id'] == $mftvalue['id']) { $pathname = $mftvalue['base_url']; $baseUrlKeyMediaArray[$pathname] = $mavalue; $match = true; } } if(! $match) { $NotbaseUrlKeyMediaArray[] = $mavalue; } } print_r($baseUrlKeyMediaArray); echo "<br />"; print_r($NotbaseUrlKeyMediaArray);
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [second_url] => Array ( [file_type_id] => second file [other_stuff] => second other ) ) <br />Array ( [0] => Array ( [file_type_id] => first file [other_stuff] => first other ) )