3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $data = array( "item1"=>"1", "item2"=>"3", "item3"=>"8", "item4"=>"2", "item5"=>"4" ); $sortingArr = array("8","4","5","2","1"); $keys = array_flip($sortingArr); usort($data, function ($a, $b) use ($keys) { return $keys[$a] > $keys[$b] ? 1 : -1; }); print_r($data);
Output for 7.0.0 - 7.3.0rc3
Notice: Undefined offset: 3 in /in/HeNuJ on line 16 Notice: Undefined offset: 3 in /in/HeNuJ on line 16 Notice: Undefined offset: 3 in /in/HeNuJ on line 16 Notice: Undefined offset: 3 in /in/HeNuJ on line 16 Array ( [0] => 8 [1] => 3 [2] => 4 [3] => 2 [4] => 1 )
Output for hhvm-3.20.2, hhvm-3.22.0
Notice: Undefined index: 3 in /in/HeNuJ on line -1 Notice: Undefined index: 3 in /in/HeNuJ on line -1 Array ( [0] => 3 [1] => 8 [2] => 4 [3] => 2 [4] => 1 )
Output for hhvm-3.15.4 - 3.19.2, hhvm-3.21.0 - 3.21.3
Notice: Undefined index: 3 in /in/HeNuJ on line 16 Notice: Undefined index: 3 in /in/HeNuJ on line 16 Array ( [0] => 3 [1] => 8 [2] => 4 [3] => 2 [4] => 1 )
Output for 5.6.30
Notice: Undefined offset: 3 in /in/HeNuJ on line 16 Notice: Undefined offset: 3 in /in/HeNuJ on line 16 Array ( [0] => 3 [1] => 8 [2] => 4 [3] => 2 [4] => 1 )