3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace x { define('x\_', bin2hex(random_bytes(128))); function partial(callable $f, ...$x) { return static function (...$y) use ($f, $x) { // replace every placeholder with the next passed parameter $x = array_map( function ($a) use (&$y) { return _ === $a ? array_shift($y) : $a; }, $x ); // append any remaining parameters $x = array_merge($x, $y); return $f(...$x); }; } } namespace { use const x\_; use function x\partial; $cube = partial('pow', _, 3); var_dump($cube(2)); $dash = partial('implode', '-'); var_dump($dash([1,2,3])); }
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.30, 7.4.0 - 7.4.24, 8.0.0 - 8.0.11
int(8) string(5) "1-2-3"

preferences:
53.92 ms | 406 KiB | 5 Q