3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $template = ['A', 'B', 'C']; $myArray = [ new Element('B'), new Element('C'), new Element('A'), ]; class Element { public $name; public function __construct($name) { $this->name = $name; } } usort($myArray, function($a, $b) use ($template) { return array_search($template, $a) - array_search($template, $b); }); var_dump($myArray);
based on dDb8T
Output for 7.0.0 - 7.2.0
Warning: array_search() expects parameter 2 to be array, object given in /in/FnY8k on line 22 Warning: array_search() expects parameter 2 to be array, object given in /in/FnY8k on line 22 Warning: array_search() expects parameter 2 to be array, object given in /in/FnY8k on line 22 Warning: array_search() expects parameter 2 to be array, object given in /in/FnY8k on line 22 array(3) { [0]=> object(Element)#1 (1) { ["name"]=> string(1) "B" } [1]=> object(Element)#2 (1) { ["name"]=> string(1) "C" } [2]=> object(Element)#3 (1) { ["name"]=> string(1) "A" } }
Output for 5.4.2 - 5.6.28
Warning: array_search() expects parameter 2 to be array, object given in /in/FnY8k on line 22 Warning: array_search() expects parameter 2 to be array, object given in /in/FnY8k on line 22 Warning: array_search() expects parameter 2 to be array, object given in /in/FnY8k on line 22 Warning: array_search() expects parameter 2 to be array, object given in /in/FnY8k on line 22 array(3) { [0]=> object(Element)#3 (1) { ["name"]=> string(1) "A" } [1]=> object(Element)#2 (1) { ["name"]=> string(1) "C" } [2]=> object(Element)#1 (1) { ["name"]=> string(1) "B" } }
Output for 5.3.18 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/FnY8k on line 4
Process exited with code 255.