3v4l.org

run code in 300+ PHP versions simultaneously
<?php function createMultiKeyCmpFunc($cmp, $key /* , keys... */) { $keys = func_get_args(); array_shift($keys); return function (array $a, array $b) use ($cmp, $keys) { return array_reduce($keys, function ($result, $key) use ($cmp, $a, $b) { return $result ?: call_user_func($cmp, $a[$key], $b[$key]); }); }; } $array = [ ['foo' => 4, 'bar' => 2, 'baz' => 3], ['foo' => 4, 'bar' => 3, 'baz' => 3], ['foo' => 3, 'bar' => 2, 'baz' => 3], ['foo' => 4, 'bar' => 1, 'baz' => 6], ['foo' => 3, 'bar' => 2, 'baz' => 3], ['foo' => 1, 'bar' => 4, 'baz' => 3], ['foo' => 2, 'bar' => 2, 'baz' => 1], ['foo' => 6, 'bar' => 6, 'baz' => 8], ['foo' => 6, 'bar' => 2, 'baz' => 3], ['foo' => 3, 'bar' => 1, 'baz' => 5], ['foo' => 4, 'bar' => 2, 'baz' => 3], ]; usort($array, createMultiKeyCmpFunc('strcmp', 'foo', 'bar', 'baz')); var_dump($array);
Output for git.master, git.master_jit, rfc.property-hooks
array(11) { [0]=> array(3) { ["foo"]=> int(1) ["bar"]=> int(4) ["baz"]=> int(3) } [1]=> array(3) { ["foo"]=> int(2) ["bar"]=> int(2) ["baz"]=> int(1) } [2]=> array(3) { ["foo"]=> int(3) ["bar"]=> int(1) ["baz"]=> int(5) } [3]=> array(3) { ["foo"]=> int(3) ["bar"]=> int(2) ["baz"]=> int(3) } [4]=> array(3) { ["foo"]=> int(3) ["bar"]=> int(2) ["baz"]=> int(3) } [5]=> array(3) { ["foo"]=> int(4) ["bar"]=> int(1) ["baz"]=> int(6) } [6]=> array(3) { ["foo"]=> int(4) ["bar"]=> int(2) ["baz"]=> int(3) } [7]=> array(3) { ["foo"]=> int(4) ["bar"]=> int(2) ["baz"]=> int(3) } [8]=> array(3) { ["foo"]=> int(4) ["bar"]=> int(3) ["baz"]=> int(3) } [9]=> array(3) { ["foo"]=> int(6) ["bar"]=> int(2) ["baz"]=> int(3) } [10]=> array(3) { ["foo"]=> int(6) ["bar"]=> int(6) ["baz"]=> int(8) } }

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:
52.1 ms | 403 KiB | 8 Q