3v4l.org

run code in 300+ PHP versions simultaneously
<?php $args = array( 'a' => array( 'zebra' => 1, ), 'b' => array( 'zebra' => 0, ), 'c' => array( 'zebra' => 0, ), 'd' => array( 'zebra' => 0, ), 'e' => array( 'zebra' => 1, ), ); $zeros = []; $ones = []; foreach($args as $let=>$arg){ if ($arg['zebra'] === 1) { $ones[] = $let; } else if ($arg['zebra'] === 0) { $zeros[] = $let; } } $res = []; if(abs(count($zeros) - count($ones)) === 1) { if (count($ones) > count($zeros)){ foreach($zeros as $ind=>$let){ $res[$ones[$ind]] = ['zebra' => 1]; $res[$let] = ['zebra' => 0]; $tmp = $ind; } $res[$ones[$tmp+1]] = ['zebra' => 1]; } else if (count($ones) < count($zeros)){ foreach($ones as $ind=>$let){ $res[$zeros[$ind]] = ['zebra' => 0]; $res[$let] = ['zebra' => 1]; $tmp = $ind; } $res[$zeros[$tmp+1]] = ['zebra' => 0]; } } print_r($res);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 18
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 18
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 17
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 67
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 48
Branch analysis from position: 32
2 jumps found. (Code = 77) Position 1 = 33, Position 2 = 42
Branch analysis from position: 33
2 jumps found. (Code = 78) Position 1 = 34, Position 2 = 42
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
Branch analysis from position: 48
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 67
Branch analysis from position: 52
2 jumps found. (Code = 77) Position 1 = 53, Position 2 = 62
Branch analysis from position: 53
2 jumps found. (Code = 78) Position 1 = 54, Position 2 = 62
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
Branch analysis from position: 67
Branch analysis from position: 67
Branch analysis from position: 18
filename:       /in/D3FO1
function name:  (null)
number of ops:  71
compiled vars:  !0 = $args, !1 = $zeros, !2 = $ones, !3 = $arg, !4 = $let, !5 = $res, !6 = $ind, !7 = $tmp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   21     1        ASSIGN                                                   !1, <array>
   22     2        ASSIGN                                                   !2, <array>
   24     3      > FE_RESET_R                                       $11     !0, ->18
          4    > > FE_FETCH_R                                       ~12     $11, !3, ->18
          5    >   ASSIGN                                                   !4, ~12
   25     6        FETCH_DIM_R                                      ~14     !3, 'zebra'
          7        IS_IDENTICAL                                             ~14, 1
          8      > JMPZ                                                     ~15, ->12
   26     9    >   ASSIGN_DIM                                               !2
         10        OP_DATA                                                  !4
   25    11      > JMP                                                      ->17
   27    12    >   FETCH_DIM_R                                      ~17     !3, 'zebra'
         13        IS_IDENTICAL                                             ~17, 0
         14      > JMPZ                                                     ~18, ->17
   28    15    >   ASSIGN_DIM                                               !1
         16        OP_DATA                                                  !4
   24    17    > > JMP                                                      ->4
         18    >   FE_FREE                                                  $11
   32    19        ASSIGN                                                   !5, <array>
   33    20        INIT_FCALL                                               'abs'
         21        COUNT                                            ~21     !1
         22        COUNT                                            ~22     !2
         23        SUB                                              ~23     ~21, ~22
         24        SEND_VAL                                                 ~23
         25        DO_ICALL                                         $24     
         26        IS_IDENTICAL                                             $24, 1
         27      > JMPZ                                                     ~25, ->67
   34    28    >   COUNT                                            ~26     !2
         29        COUNT                                            ~27     !1
         30        IS_SMALLER                                               ~27, ~26
         31      > JMPZ                                                     ~28, ->48
   35    32    > > FE_RESET_R                                       $29     !1, ->42
         33    > > FE_FETCH_R                                       ~30     $29, !4, ->42
         34    >   ASSIGN                                                   !6, ~30
   36    35        FETCH_DIM_R                                      ~32     !2, !6
         36        ASSIGN_DIM                                               !5, ~32
         37        OP_DATA                                                  <array>
   37    38        ASSIGN_DIM                                               !5, !4
         39        OP_DATA                                                  <array>
   38    40        ASSIGN                                                   !7, !6
   35    41      > JMP                                                      ->33
         42    >   FE_FREE                                                  $29
   40    43        ADD                                              ~36     !7, 1
         44        FETCH_DIM_R                                      ~37     !2, ~36
         45        ASSIGN_DIM                                               !5, ~37
         46        OP_DATA                                                  <array>
   34    47      > JMP                                                      ->67
   41    48    >   COUNT                                            ~39     !2
         49        COUNT                                            ~40     !1
         50        IS_SMALLER                                               ~39, ~40
         51      > JMPZ                                                     ~41, ->67
   42    52    > > FE_RESET_R                                       $42     !2, ->62
         53    > > FE_FETCH_R                                       ~43     $42, !4, ->62
         54    >   ASSIGN                                                   !6, ~43
   43    55        FETCH_DIM_R                                      ~45     !1, !6
         56        ASSIGN_DIM                                               !5, ~45
         57        OP_DATA                                                  <array>
   44    58        ASSIGN_DIM                                               !5, !4
         59        OP_DATA                                                  <array>
   45    60        ASSIGN                                                   !7, !6
   42    61      > JMP                                                      ->53
         62    >   FE_FREE                                                  $42
   47    63        ADD                                              ~49     !7, 1
         64        FETCH_DIM_R                                      ~50     !1, ~49
         65        ASSIGN_DIM                                               !5, ~50
         66        OP_DATA                                                  <array>
   51    67    >   INIT_FCALL                                               'print_r'
         68        SEND_VAR                                                 !5
         69        DO_ICALL                                                 
         70      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
272.6 ms | 1020 KiB | 15 Q