3v4l.org

run code in 300+ PHP versions simultaneously
<?php $players = array ( 0 => array ( 'ID' => '3', 'name' => 'olaf', 'team' => NULL, ), 1 => array ( 'ID' => '4', 'name' => 'Peter', 'team' => NULL, ), 2 => array ( 'ID' => '5', 'name' => 'chris', 'team' => NULL, ), 3 => array ( 'ID' => '6', 'name' => 'günther', 'team' => NULL, ), 4 => array ( 'ID' => '7', 'name' => 'John', 'team' => NULL, ), 5 => array ( 'ID' => '8', 'name' => 'Jack', 'team' => NULL, ), 6 => array ( 'ID' => '9', 'name' => 'Bob', 'team' => NULL, ), 7 => array ( 'ID' => '10', 'name' => 'Jake', 'team' => NULL, ), 8 => array ( 'ID' => '11', 'name' => 'Bill', 'team' => NULL, ) ) ; function constTeams($players){ $numOfPlayers = count($players); $check = array(); $i = 0; while($i < count($players)){ foreach($players as $key => $value){ $random = rand(1,$numOfPlayers); if(!in_array($random, $check) && !array_key_exists($value['name'], $check)){ $check[$value['name']] = $random; $i++; } } } if(count($check) === count($players)){ // no assign team $teamOne = '<br>Team one: '; $teamTwo = '<br>Team two: '; foreach($players as $key => $value){ $gamers[$key] = $value; if($check[$value['name']] % 2 == 0){ $gamers[$key]['team'] = 'Blue'; }else{ $gamers[$key]['team'] = 'Red'; } } } return $gamers; } $output = ' <table> '; foreach(constTeams($players) as $key => $value){ $style = ($value['team'] === 'Red') ? ' style="background-color: #fc7777; color: #610202;"' : ' style="background-color: lightblue; color: darkblue"'; $output .= ' <tr border="1"> <td'.$style.'>'.$value['name'].'</td> </tr>'; } $output .= ' </table>'; echo $output;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 22
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 22
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/ZUl5p
function name:  (null)
number of ops:  26
compiled vars:  !0 = $players, !1 = $output, !2 = $value, !3 = $key, !4 = $style
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   45     1        ASSIGN                                                   !1, '%0A++%3Ctable%3E%0A++++'
   48     2        INIT_FCALL                                               'constteams'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $7      
          5      > FE_RESET_R                                       $8      $7, ->22
          6    > > FE_FETCH_R                                       ~9      $8, !2, ->22
          7    >   ASSIGN                                                   !3, ~9
   49     8        FETCH_DIM_R                                      ~11     !2, 'team'
          9        IS_IDENTICAL                                             ~11, 'Red'
         10      > JMPZ                                                     ~12, ->13
         11    >   QM_ASSIGN                                        ~13     '+style%3D%22background-color%3A+%23fc7777%3B+color%3A+%23610202%3B%22'
         12      > JMP                                                      ->14
         13    >   QM_ASSIGN                                        ~13     '+style%3D%22background-color%3A+lightblue%3B+color%3A+darkblue%22'
         14    >   ASSIGN                                                   !4, ~13
   52    15        CONCAT                                           ~15     '%0A++++++%3Ctr+border%3D%221%22%3E%0A++++++++%3Ctd', !4
         16        CONCAT                                           ~16     ~15, '%3E'
         17        FETCH_DIM_R                                      ~17     !2, 'name'
         18        CONCAT                                           ~18     ~16, ~17
         19        CONCAT                                           ~19     ~18, '%3C%2Ftd%3E%0A++++++%3C%2Ftr%3E'
         20        ASSIGN_OP                                     8          !1, ~19
   48    21      > JMP                                                      ->6
         22    >   FE_FREE                                                  $8
   55    23        ASSIGN_OP                                     8          !1, '%0A++%3C%2Ftable%3E'
   58    24        ECHO                                                     !1
   59    25      > RETURN                                                   1

Function constteams:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 6
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 59
Branch analysis from position: 38
2 jumps found. (Code = 77) Position 1 = 41, Position 2 = 58
Branch analysis from position: 41
2 jumps found. (Code = 78) Position 1 = 42, Position 2 = 58
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 50, Position 2 = 54
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 58
Branch analysis from position: 59
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 30
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 30
Branch analysis from position: 8
2 jumps found. (Code = 46) Position 1 = 20, Position 2 = 24
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 29
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 29
Branch analysis from position: 24
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 6
Branch analysis from position: 34
Branch analysis from position: 6
Branch analysis from position: 30
filename:       /in/ZUl5p
function name:  constTeams
number of ops:  61
compiled vars:  !0 = $players, !1 = $numOfPlayers, !2 = $check, !3 = $i, !4 = $value, !5 = $key, !6 = $random, !7 = $teamOne, !8 = $teamTwo, !9 = $gamers
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        COUNT                                            ~10     !0
          2        ASSIGN                                                   !1, ~10
   17     3        ASSIGN                                                   !2, <array>
   19     4        ASSIGN                                                   !3, 0
   20     5      > JMP                                                      ->31
   21     6    > > FE_RESET_R                                       $14     !0, ->30
          7    > > FE_FETCH_R                                       ~15     $14, !4, ->30
          8    >   ASSIGN                                                   !5, ~15
   22     9        INIT_FCALL                                               'rand'
         10        SEND_VAL                                                 1
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                         $17     
         13        ASSIGN                                                   !6, $17
   23    14        INIT_FCALL                                               'in_array'
         15        SEND_VAR                                                 !6
         16        SEND_VAR                                                 !2
         17        DO_ICALL                                         $19     
         18        BOOL_NOT                                         ~20     $19
         19      > JMPZ_EX                                          ~20     ~20, ->24
         20    >   FETCH_DIM_R                                      ~21     !4, 'name'
         21        ARRAY_KEY_EXISTS                                 ~22     ~21, !2
         22        BOOL_NOT                                         ~23     ~22
         23        BOOL                                             ~20     ~23
         24    > > JMPZ                                                     ~20, ->29
   24    25    >   FETCH_DIM_R                                      ~24     !4, 'name'
         26        ASSIGN_DIM                                               !2, ~24
         27        OP_DATA                                                  !6
   25    28        PRE_INC                                                  !3
   21    29    > > JMP                                                      ->7
         30    >   FE_FREE                                                  $14
   20    31    >   COUNT                                            ~27     !0
         32        IS_SMALLER                                               !3, ~27
         33      > JMPNZ                                                    ~28, ->6
   29    34    >   COUNT                                            ~29     !2
         35        COUNT                                            ~30     !0
         36        IS_IDENTICAL                                             ~29, ~30
         37      > JMPZ                                                     ~31, ->59
   31    38    >   ASSIGN                                                   !7, '%3Cbr%3ETeam+one%3A+'
   32    39        ASSIGN                                                   !8, '%3Cbr%3ETeam+two%3A+'
   33    40      > FE_RESET_R                                       $34     !0, ->58
         41    > > FE_FETCH_R                                       ~35     $34, !4, ->58
         42    >   ASSIGN                                                   !5, ~35
   34    43        ASSIGN_DIM                                               !9, !5
         44        OP_DATA                                                  !4
   35    45        FETCH_DIM_R                                      ~38     !4, 'name'
         46        FETCH_DIM_R                                      ~39     !2, ~38
         47        MOD                                              ~40     ~39, 2
         48        IS_EQUAL                                                 ~40, 0
         49      > JMPZ                                                     ~41, ->54
   36    50    >   FETCH_DIM_W                                      $42     !9, !5
         51        ASSIGN_DIM                                               $42, 'team'
         52        OP_DATA                                                  'Blue'
   35    53      > JMP                                                      ->57
   38    54    >   FETCH_DIM_W                                      $44     !9, !5
         55        ASSIGN_DIM                                               $44, 'team'
         56        OP_DATA                                                  'Red'
   33    57    > > JMP                                                      ->41
         58    >   FE_FREE                                                  $34
   42    59    > > RETURN                                                   !9
   43    60*     > RETURN                                                   null

End of function constteams

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.28 ms | 1023 KiB | 16 Q