3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [2,2,2,1,1,0,0,8]; $values_cache = []; usort($array, function ($a, $b) use (&$values_cache) { $key_a = isset($values_cache[$a]) ? $values_cache[$a] : ($values_cache[$a] = keyfn($a)); $key_b = isset($values_cache[$b]) ? $values_cache[$b] : ($values_cache[$b] = keyfn($b)); return $key_a <=> $key_b; }); echo '<pre>', print_r($array), '</pre>'; // TODO function keyfn($v) { echo 'call a keyfn' . PHP_EOL; return 2 * $v; }
Output for git.master_jit, git.master, rfc.property-hooks
call a keyfn call a keyfn call a keyfn call a keyfn <pre>Array ( [0] => 0 [1] => 0 [2] => 1 [3] => 1 [4] => 2 [5] => 2 [6] => 2 [7] => 8 ) 1</pre>

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:
60.34 ms | 401 KiB | 8 Q