3v4l.org

run code in 300+ PHP versions simultaneously
<?php function battle($a, $b) { if ($a > 2 || $b > 2) { $a = (int)($a / 3); $b = (int)($b / 3); } return ($a - $b + 3) % 3; } $hand_list = array( 0 => 'グー', 1 => 'チョキ', 2 => 'パー', 3 => '奴隷', 6 => '皇帝', ); $result_list = array( 2 => 'あなたの勝ちです', 1 => 'あなたの負けです', 0 => 'あいこです', -1 => '不明', ); // 手が送信されたとき勝負を実行 if (isset($_POST['you'])) { // 整数型にキャスト(不正な値をエラー無しに防ぐ効果もある) $you = (int)$_POST['you']; // コンピュータの手を選出 $com = array_rand($hand_list); if (!isset($hand_list[$you])) { // 不正な値のときは自分の手を「?」、結果を「不明」にする $hand_list[$you = -1] = '?'; $result = -1; } else { // 正しい値のときは関数に渡す $result = battle($you, $com); } } // ヘッダー送信 header('Content-Type: application/xhtml+xml; charset=utf-8'); ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" lang="ja"> <head> <title>じゃんけんゲーム</title> <style type="text/css"> label { display: block; } </style> </head> <body> <h1>じゃんけん</h1> <form action="<?=basename($_SERVER['SCRIPT_NAME'])?>" method="post"> <label><input type="radio" name="you" value="0" checked="checked" />グー</label> <label><input type="radio" name="you" value="1" />チョキ</label> <label><input type="radio" name="you" value="2" />パー</label> <label><input type="radio" name="you" value="6" />皇帝</label> <label><input type="radio" name="you" value="3" />奴隷</label> <label><input type="submit" value="勝負!" /></label> </form> <?php if (isset($result)): ?> <h1>勝負!</h1> <p> あなた: <?=$hand_list[$you]?><br /> コンピュータ: <?=$hand_list[$com]?><br /> <?=$result_list[$result]."\n"?> </p> <?php endif; //isset($result)がTrueのときだけ上記を表示できる ?> </body> </html>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 26
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 21
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 50
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 50
Branch analysis from position: 39
Branch analysis from position: 50
Branch analysis from position: 26
filename:       /in/lj3pu
function name:  (null)
number of ops:  52
compiled vars:  !0 = $hand_list, !1 = $result_list, !2 = $you, !3 = $com, !4 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   ASSIGN                                                   !0, <array>
   19     1        ASSIGN                                                   !1, <array>
   27     2        FETCH_IS                                         ~7      '_POST'
          3        ISSET_ISEMPTY_DIM_OBJ                         0          ~7, 'you'
          4      > JMPZ                                                     ~8, ->26
   29     5    >   FETCH_R                      global              ~9      '_POST'
          6        FETCH_DIM_R                                      ~10     ~9, 'you'
          7        CAST                                          4  ~11     ~10
          8        ASSIGN                                                   !2, ~11
   31     9        INIT_FCALL                                               'array_rand'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $13     
         12        ASSIGN                                                   !3, $13
   32    13        ISSET_ISEMPTY_DIM_OBJ                         0  ~15     !0, !2
         14        BOOL_NOT                                         ~16     ~15
         15      > JMPZ                                                     ~16, ->21
   34    16    >   ASSIGN                                           ~17     !2, -1
         17        ASSIGN_DIM                                               !0, ~17
         18        OP_DATA                                                  '%EF%BC%9F'
   35    19        ASSIGN                                                   !4, -1
         20      > JMP                                                      ->26
   38    21    >   INIT_FCALL                                               'battle'
         22        SEND_VAR                                                 !2
         23        SEND_VAR                                                 !3
         24        DO_FCALL                                      0  $20     
         25        ASSIGN                                                   !4, $20
   43    26    >   INIT_FCALL                                               'header'
         27        SEND_VAL                                                 'Content-Type%3A+application%2Fxhtml%2Bxml%3B+charset%3Dutf-8'
         28        DO_ICALL                                                 
   46    29        ECHO                                                     '%3C%21DOCTYPE+html%3E%0A%3Chtml+xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22+lang%3D%22ja%22%3E%0A++%3Chead%3E%0A++++%3Ctitle%3E%E3%81%98%E3%82%83%E3%82%93%E3%81%91%E3%82%93%E3%82%B2%E3%83%BC%E3%83%A0%3C%2Ftitle%3E%0A++++%3Cstyle+type%3D%22text%2Fcss%22%3E%0A++++++label+%7B+display%3A+block%3B+%7D%0A++++%3C%2Fstyle%3E%0A++%3C%2Fhead%3E%0A++%3Cbody%3E%0A++++%3Ch1%3E%E3%81%98%E3%82%83%E3%82%93%E3%81%91%E3%82%93%3C%2Fh1%3E%0A++++%3Cform+action%3D%22'
   56    30        INIT_FCALL                                               'basename'
         31        FETCH_R                      global              ~23     '_SERVER'
         32        FETCH_DIM_R                                      ~24     ~23, 'SCRIPT_NAME'
         33        SEND_VAL                                                 ~24
         34        DO_ICALL                                         $25     
         35        ECHO                                                     $25
         36        ECHO                                                     '%22+method%3D%22post%22%3E%0A++++++%3Clabel%3E%3Cinput+type%3D%22radio%22+name%3D%22you%22+value%3D%220%22+checked%3D%22checked%22+%2F%3E%E3%82%B0%E3%83%BC%3C%2Flabel%3E%0A++++++%3Clabel%3E%3Cinput+type%3D%22radio%22+name%3D%22you%22+value%3D%221%22+%2F%3E%E3%83%81%E3%83%A7%E3%82%AD%3C%2Flabel%3E%0A++++++%3Clabel%3E%3Cinput+type%3D%22radio%22+name%3D%22you%22+value%3D%222%22+%2F%3E%E3%83%91%E3%83%BC%3C%2Flabel%3E%0A++++++%3Clabel%3E%3Cinput+type%3D%22radio%22+name%3D%22you%22+value%3D%226%22+%2F%3E%E7%9A%87%E5%B8%9D%3C%2Flabel%3E%0A++++++%3Clabel%3E%3Cinput+type%3D%22radio%22+name%3D%22you%22+value%3D%223%22+%2F%3E%E5%A5%B4%E9%9A%B7%3C%2Flabel%3E%0A++++++%3Clabel%3E%3Cinput+type%3D%22submit%22+value%3D%22%E5%8B%9D%E8%B2%A0%EF%BC%81%22+%2F%3E%3C%2Flabel%3E%0A++++%3C%2Fform%3E%0A++++%0A'
   65    37        ISSET_ISEMPTY_CV                                         !4
         38      > JMPZ                                                     ~26, ->50
   66    39    >   ECHO                                                     '++++%3Ch1%3E%E5%8B%9D%E8%B2%A0%EF%BC%81%3C%2Fh1%3E%0A++++%3Cp%3E%0A++++++%E3%81%82%E3%81%AA%E3%81%9F%EF%BC%9A+'
   68    40        FETCH_DIM_R                                      ~27     !0, !2
         41        ECHO                                                     ~27
         42        ECHO                                                     '%3Cbr+%2F%3E%0A++++++%E3%82%B3%E3%83%B3%E3%83%94%E3%83%A5%E3%83%BC%E3%82%BF%3A+'
   69    43        FETCH_DIM_R                                      ~28     !0, !3
         44        ECHO                                                     ~28
         45        ECHO                                                     '%3Cbr+%2F%3E%0A++++++'
   70    46        FETCH_DIM_R                                      ~29     !1, !4
         47        CONCAT                                           ~30     ~29, '%0A'
         48        ECHO                                                     ~30
   71    49        ECHO                                                     '++++%3C%2Fp%3E%0A'
   73    50    >   ECHO                                                     '++%3C%2Fbody%3E%0A%3C%2Fhtml%3E'
   74    51      > RETURN                                                   1

Function battle:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 13
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
Branch analysis from position: 6
filename:       /in/lj3pu
function name:  battle
number of ops:  18
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        IS_SMALLER                                       ~2      2, !0
          3      > JMPNZ_EX                                         ~2      ~2, ->6
          4    >   IS_SMALLER                                       ~3      2, !1
          5        BOOL                                             ~2      ~3
          6    > > JMPZ                                                     ~2, ->13
    5     7    >   DIV                                              ~4      !0, 3
          8        CAST                                          4  ~5      ~4
          9        ASSIGN                                                   !0, ~5
    6    10        DIV                                              ~7      !1, 3
         11        CAST                                          4  ~8      ~7
         12        ASSIGN                                                   !1, ~8
    8    13    >   SUB                                              ~10     !0, !1
         14        ADD                                              ~11     ~10, 3
         15        MOD                                              ~12     ~11, 3
         16      > RETURN                                                   ~12
    9    17*     > RETURN                                                   null

End of function battle

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.65 ms | 1407 KiB | 20 Q