3v4l.org

run code in 300+ PHP versions simultaneously
<?php $options = ['paper', 'rock', 'scissors']; $lookup = array_flip($options); $outcomes = ['draw', 'win', 'lose']; // only extract a random value if the player has selected an option -- otherwise there is no comparison executed. $cpuSelection = $options[array_rand($options)]; $playerSelection = 'rock'; $comparison = $lookup[$cpuSelection] - $lookup[$playerSelection]; var_export([ 'cpu' => $cpuSelection, 'human' => $playerSelection, 'outcome' => $outcomes[($comparison + 3) % 3] ]);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HGZBn
function name:  (null)
number of ops:  26
compiled vars:  !0 = $options, !1 = $lookup, !2 = $outcomes, !3 = $cpuSelection, !4 = $playerSelection, !5 = $comparison
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        INIT_FCALL                                               'array_flip'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $7      
          4        ASSIGN                                                   !1, $7
    5     5        ASSIGN                                                   !2, <array>
    7     6        INIT_FCALL                                               'array_rand'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $10     
          9        FETCH_DIM_R                                      ~11     !0, $10
         10        ASSIGN                                                   !3, ~11
    8    11        ASSIGN                                                   !4, 'rock'
   10    12        FETCH_DIM_R                                      ~14     !1, !3
         13        FETCH_DIM_R                                      ~15     !1, !4
         14        SUB                                              ~16     ~14, ~15
         15        ASSIGN                                                   !5, ~16
   11    16        INIT_FCALL                                               'var_export'
   12    17        INIT_ARRAY                                       ~18     !3, 'cpu'
   13    18        ADD_ARRAY_ELEMENT                                ~18     !4, 'human'
   14    19        ADD                                              ~19     !5, 3
         20        MOD                                              ~20     ~19, 3
         21        FETCH_DIM_R                                      ~21     !2, ~20
         22        ADD_ARRAY_ELEMENT                                ~18     ~21, 'outcome'
         23        SEND_VAL                                                 ~18
         24        DO_ICALL                                                 
   15    25      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.51 ms | 1399 KiB | 19 Q