3v4l.org

run code in 300+ PHP versions simultaneously
<?php function partial(callable $callable, ...$initialargs): callable { return fn (...$args) => $callable(...$initialargs, ...$args); } $data = [ [ 'quiz' => 2, 'question' => 7, 'notif' => 'sup' ], [ 'quiz' => 3, 'question' => 7, 'notif' => 'pus' ], [ 'quiz' => 2, 'question' => 3, 'notif' => 'yoyoyo' ] ]; $keys = fn(array $data, string $key): callable => partial(array_keys(...), array_column($data, $key)); $indices = fn(array $data, string $key): array => array_map($keys($data, $key), array_column($data, $key, $key)); $map = fn(array $data): callable => partial(array_map(...), fn(int $i): array => $data[$i]); $byx = fn(array $data, string $x): array => array_map($map, $indices($data, $x)); $byquiz = $byx($data, 'quiz'); $byquizandquestion = array_map(fn($d) => $byx($d, 'question'), $byquiz); print_r($byquizandquestion);
Output for 8.1.0 - 8.1.30, 8.2.0 - 8.2.24, 8.3.0 - 8.3.12
Fatal error: Uncaught TypeError: {closure}(): Argument #1 ($data) must be of type array, Closure given, called in /in/McAek on line 31 and defined in /in/McAek:28 Stack trace: #0 /in/McAek(31): {closure}(Object(Closure), 'question') #1 [internal function]: {closure}(Object(Closure)) #2 /in/McAek(31): array_map(Object(Closure), Array) #3 {main} thrown in /in/McAek on line 28
Process exited with code 255.

preferences:
46.93 ms | 407 KiB | 5 Q