3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $order = array( 3452342, 5867867, 7867867, 1231233 ); $array = array( array("id" => 7867867, "title" => "Must Be #3"), array("id" => 3452342, "title" => "Must Be #1"), array("id" => 1231233, "title" => "Must Be #4"), array("id" => 5867867, "title" => "Must Be #2"), array("id" => 1111111, "title" => "Dont Care #1"), array("id" => 2222222, "title" => "Dont Care #2"), array("id" => 3333333, "title" => "Dont Care #3"), array("id" => 4444444, "title" => "Dont Care #4") ); function custom_compare($a, $b){ global $order; $a = array_search($a["id"], $order); $b = array_search($b["id"], $order); if($a === false && $b === false) { // both items are dont cares return 0; // a == b } else if ($a === false) { // $a is a dont care item return 1; // $a > $b } else if ($b === false) { // $b is a dont care item return -1; // $a < $b } else { return $a - $b; } } foreach($array as $arrays): echo $array["id"]; echo $array["title"]; endforeach;?> ?>
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Notice: Undefined index: id in /in/Y7iFc on line 38 Notice: Undefined index: title in /in/Y7iFc on line 39 Notice: Undefined index: id in /in/Y7iFc on line 38 Notice: Undefined index: title in /in/Y7iFc on line 39 Notice: Undefined index: id in /in/Y7iFc on line 38 Notice: Undefined index: title in /in/Y7iFc on line 39 Notice: Undefined index: id in /in/Y7iFc on line 38 Notice: Undefined index: title in /in/Y7iFc on line 39 Notice: Undefined index: id in /in/Y7iFc on line 38 Notice: Undefined index: title in /in/Y7iFc on line 39 Notice: Undefined index: id in /in/Y7iFc on line 38 Notice: Undefined index: title in /in/Y7iFc on line 39 Notice: Undefined index: id in /in/Y7iFc on line 38 Notice: Undefined index: title in /in/Y7iFc on line 39 Notice: Undefined index: id in /in/Y7iFc on line 38 Notice: Undefined index: title in /in/Y7iFc on line 39 ?>
Output for 4.3.0 - 5.2.17
Notice: Undefined index: id in /in/Y7iFc on line 38 Notice: Undefined index: title in /in/Y7iFc on line 39 Notice: Undefined index: id in /in/Y7iFc on line 38 Notice: Undefined index: title in /in/Y7iFc on line 39 Notice: Undefined index: id in /in/Y7iFc on line 38 Notice: Undefined index: title in /in/Y7iFc on line 39 Notice: Undefined index: id in /in/Y7iFc on line 38 Notice: Undefined index: title in /in/Y7iFc on line 39 Notice: Undefined index: id in /in/Y7iFc on line 38 Notice: Undefined index: title in /in/Y7iFc on line 39 Notice: Undefined index: id in /in/Y7iFc on line 38 Notice: Undefined index: title in /in/Y7iFc on line 39 Notice: Undefined index: id in /in/Y7iFc on line 38 Notice: Undefined index: title in /in/Y7iFc on line 39 Notice: Undefined index: id in /in/Y7iFc on line 38 Notice: Undefined index: title in /in/Y7iFc on line 39 ?>