3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Janken; use Closure; const WIN_LOSE_TABLE = [ 'グー' => ['チョキ' => 1, 'パー' => -1], 'チョキ' => ['パー' => 1, 'グー' => -1], 'パー' => ['グー' => 1, 'チョキ' => -1], ]; const EMOJI_TABLE = [ 'グー' => '✊', 'チョキ' => '✌', 'パー' => '🖐', ]; $printer = fn(string $my_hand, string $your_hand, int $result): string => sprintf("[%s vs %s] %s", EMOJI_TABLE[$my_hand], EMOJI_TABLE[$your_hand], match ($result) { -1 => 'あなたの負け', 0 => 'あいこ', 1 => 'あなたの勝ち', } ); foreach (['グー', 'チョキ', 'パー'] as $my_hand) { foreach (['グー', 'チョキ', 'パー'] as $your_hand) { echo battle($my_hand, $your_hand, $printer), PHP_EOL; } } function battle(string $my_hand, string $your_hand, Closure $printer): string { return $printer($my_hand, $your_hand, WIN_LOSE_TABLE[$my_hand][$your_hand] ?? 0); }
Output for 8.0.0 - 8.0.3, 8.1.23 - 8.1.28, 8.2.10 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
[✊ vs ✊] あいこ [✊ vs ✌] あなたの勝ち [✊ vs 🖐] あなたの負け [✌ vs ✊] あなたの負け [✌ vs ✌] あいこ [✌ vs 🖐] あなたの勝ち [🖐 vs ✊] あなたの勝ち [🖐 vs ✌] あなたの負け [🖐 vs 🖐] あいこ
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 [✊ vs ✊] あいこ [✊ vs ✌] あなたの勝ち [✊ vs 🖐] あなたの負け [✌ vs ✊] あなたの負け [✌ vs ✌] あいこ [✌ vs 🖐] あなたの勝ち [🖐 vs ✊] あなたの勝ち [🖐 vs ✌] あなたの負け [🖐 vs 🖐] あいこ
Output for 7.4.0 - 7.4.16
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in /in/MFqsQ on line 24
Process exited with code 255.
Output for 7.3.0 - 7.3.27
Parse error: syntax error, unexpected '$my_hand' (T_VARIABLE), expecting ')' in /in/MFqsQ on line 19
Process exited with code 255.

preferences:
102.36 ms | 401 KiB | 76 Q