3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class SortMadness { private $data; public function __construct($data) { $this->data = $data; } public function __toString() { //$data = array_map(function($item) { return $item; }, $this->data); $data = array_merge($this->data); sort($data); $rs = implode('-', $data); echo $rs."\n"; return $rs; } } // expected order is ['a','b'],['c','b','a'],['c','b'] $a = array( new SortMadness(array('c','b')), new SortMadness(array('c','b','a')), new SortMadness(array('a','b')), ); sort($a); print_r($a); usort($a, 'strcmp'); print_r($a);
based on Fv182
Output for 7.0.0 - 7.2.0
Array ( [0] => SortMadness Object ( [data:SortMadness:private] => Array ( [0] => a [1] => b ) ) [1] => SortMadness Object ( [data:SortMadness:private] => Array ( [0] => c [1] => b ) ) [2] => SortMadness Object ( [data:SortMadness:private] => Array ( [0] => c [1] => b [2] => a ) ) ) a-b b-c b-c a-b-c a-b a-b-c Array ( [0] => SortMadness Object ( [data:SortMadness:private] => Array ( [0] => a [1] => b ) ) [1] => SortMadness Object ( [data:SortMadness:private] => Array ( [0] => c [1] => b [2] => a ) ) [2] => SortMadness Object ( [data:SortMadness:private] => Array ( [0] => c [1] => b ) ) )
Output for 5.5.0 - 5.6.25
Array ( [0] => SortMadness Object ( [data:SortMadness:private] => Array ( [0] => a [1] => b ) ) [1] => SortMadness Object ( [data:SortMadness:private] => Array ( [0] => c [1] => b ) ) [2] => SortMadness Object ( [data:SortMadness:private] => Array ( [0] => c [1] => b [2] => a ) ) ) b-c a-b a-b-c b-c a-b a-b-c Array ( [0] => SortMadness Object ( [data:SortMadness:private] => Array ( [0] => a [1] => b ) ) [1] => SortMadness Object ( [data:SortMadness:private] => Array ( [0] => c [1] => b [2] => a ) ) [2] => SortMadness Object ( [data:SortMadness:private] => Array ( [0] => c [1] => b ) ) )