3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array ( "100" => array( array( "country" => 'France', "city" => 'Paris', "population" => '1800000', ), array( "country" => 'France', "city" => 'Paris', "population" => '2000000', ), array( "country" => 'France', "city" => 'Toulouse', "population" => '500000', ), ), "101" => array( array( "country" => 'Russia', "population" => '144000000', ) ) ); foreach($arr as $key => $sub){ foreach($sub as $item){ if(isset($item['city'])){ if(!isset($res[$key][$item['country'] . $item['city']])) $res[$key][$item['country'] . $item['city']] = $item; if($res[$key][$item['country'] . $item['city']] < $item['population']) $res[$key][$item['country'] . $item['city']] = $item; }else{ if(!isset($res[$key][$item['country']])) $res[$key][$item['country']] = $item; if($res[$key][$item['country']] < $item['population']) $res[$key][$item['country']] = $item; } } } var_dump($res);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 58
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 58
Branch analysis from position: 3
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 56
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 56
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 36
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 21
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 35
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 35
Branch analysis from position: 21
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 45
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 55
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 55
Branch analysis from position: 45
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 56
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 58
filename:       /in/KNuId
function name:  (null)
number of ops:  63
compiled vars:  !0 = $arr, !1 = $sub, !2 = $key, !3 = $item, !4 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   31     1      > FE_RESET_R                                       $6      !0, ->58
          2    > > FE_FETCH_R                                       ~7      $6, !1, ->58
          3    >   ASSIGN                                                   !2, ~7
   32     4      > FE_RESET_R                                       $9      !1, ->56
          5    > > FE_FETCH_R                                               $9, !3, ->56
   33     6    >   ISSET_ISEMPTY_DIM_OBJ                         0          !3, 'city'
          7      > JMPZ                                                     ~10, ->36
   34     8    >   FETCH_DIM_R                                      ~12     !3, 'country'
          9        FETCH_DIM_R                                      ~13     !3, 'city'
         10        CONCAT                                           ~14     ~12, ~13
         11        FETCH_DIM_IS                                     ~11     !4, !2
         12        ISSET_ISEMPTY_DIM_OBJ                         0  ~15     ~11, ~14
         13        BOOL_NOT                                         ~16     ~15
         14      > JMPZ                                                     ~16, ->21
         15    >   FETCH_DIM_R                                      ~18     !3, 'country'
         16        FETCH_DIM_R                                      ~19     !3, 'city'
         17        CONCAT                                           ~20     ~18, ~19
         18        FETCH_DIM_W                                      $17     !4, !2
         19        ASSIGN_DIM                                               $17, ~20
         20        OP_DATA                                                  !3
   35    21    >   FETCH_DIM_R                                      ~23     !3, 'country'
         22        FETCH_DIM_R                                      ~24     !3, 'city'
         23        CONCAT                                           ~25     ~23, ~24
         24        FETCH_DIM_R                                      ~22     !4, !2
         25        FETCH_DIM_R                                      ~26     ~22, ~25
         26        FETCH_DIM_R                                      ~27     !3, 'population'
         27        IS_SMALLER                                               ~26, ~27
         28      > JMPZ                                                     ~28, ->35
         29    >   FETCH_DIM_R                                      ~30     !3, 'country'
         30        FETCH_DIM_R                                      ~31     !3, 'city'
         31        CONCAT                                           ~32     ~30, ~31
         32        FETCH_DIM_W                                      $29     !4, !2
         33        ASSIGN_DIM                                               $29, ~32
         34        OP_DATA                                                  !3
   33    35    > > JMP                                                      ->55
   37    36    >   FETCH_DIM_R                                      ~35     !3, 'country'
         37        FETCH_DIM_IS                                     ~34     !4, !2
         38        ISSET_ISEMPTY_DIM_OBJ                         0  ~36     ~34, ~35
         39        BOOL_NOT                                         ~37     ~36
         40      > JMPZ                                                     ~37, ->45
         41    >   FETCH_DIM_R                                      ~39     !3, 'country'
         42        FETCH_DIM_W                                      $38     !4, !2
         43        ASSIGN_DIM                                               $38, ~39
         44        OP_DATA                                                  !3
   38    45    >   FETCH_DIM_R                                      ~42     !3, 'country'
         46        FETCH_DIM_R                                      ~41     !4, !2
         47        FETCH_DIM_R                                      ~43     ~41, ~42
         48        FETCH_DIM_R                                      ~44     !3, 'population'
         49        IS_SMALLER                                               ~43, ~44
         50      > JMPZ                                                     ~45, ->55
         51    >   FETCH_DIM_R                                      ~47     !3, 'country'
         52        FETCH_DIM_W                                      $46     !4, !2
         53        ASSIGN_DIM                                               $46, ~47
         54        OP_DATA                                                  !3
   32    55    > > JMP                                                      ->5
         56    >   FE_FREE                                                  $9
   31    57      > JMP                                                      ->2
         58    >   FE_FREE                                                  $6
   42    59        INIT_FCALL                                               'var_dump'
         60        SEND_VAR                                                 !4
         61        DO_ICALL                                                 
         62      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
273.93 ms | 1015 KiB | 14 Q