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 git.master, git.master_jit, rfc.property-hooks
[✊ vs ✊] あいこ [✊ vs ✌] あなたの勝ち [✊ vs 🖐] あなたの負け [✌ vs ✊] あなたの負け [✌ vs ✌] あいこ [✌ vs 🖐] あなたの勝ち [🖐 vs ✊] あなたの勝ち [🖐 vs ✌] あなたの負け [🖐 vs 🖐] あいこ

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:
34.5 ms | 402 KiB | 8 Q