3v4l.org

run code in 300+ PHP versions simultaneously
<?php $original = [ 1=>[ 1=>['brand'=> 'bmw' , 'color'=> 'white'], 171=>['brand'=> 'audi' , 'color'=> 'black'], 172=>['brand'=> 'volvo' , 'color'=> 'black'], 175=>['brand'=> 'citroen' , 'color'=> 'green'] ], 129=>[ 201=>['brand'=> 'volkswagen' , 'color'=> 'grey'], 206=>['brand'=> 'bentley' , 'color'=> 'grey'], 209=>['brand'=> 'mazda' , 'color'=> 'blue'], ], ]; $filterOnArray = [172,175,209]; $finalArray = []; foreach($original as $key=>$orig ){ $nonfiter =$orig; foreach($filterOnArray as $filterOnArr){ if(isset($orig[$filterOnArr])){ $finalArray[$key][$filterOnArr] = $orig[$filterOnArr]; unset($nonfiter[$filterOnArr]); } } $finalArray[$key] = $finalArray[$key] +$nonfiter; } print_r($finalArray);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [1] => Array ( [172] => Array ( [brand] => volvo [color] => black ) [175] => Array ( [brand] => citroen [color] => green ) [1] => Array ( [brand] => bmw [color] => white ) [171] => Array ( [brand] => audi [color] => black ) ) [129] => Array ( [209] => Array ( [brand] => mazda [color] => blue ) [201] => Array ( [brand] => volkswagen [color] => grey ) [206] => Array ( [brand] => bentley [color] => grey ) ) )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
132.61 ms | 409 KiB | 5 Q