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', "city" => 'Moscow', "population" => '144000000', ) ) ); foreach($arr as $k => &$ar) { $mins = array_reduce($ar, function ($carry, $item) { $key = $item["country"] . "###" . $item["city"]; $carry[$key] = (isset($carry[$key]) && $item["population"] > $carry[$key]) ? $carry[$key] : $item["population"]; return $carry; }, []); $ar = array_filter($ar, function ($item) use ($mins) { $key = $item["country"] . "###" . $item["city"]; return $mins[$key] == $item["population"]; }); } print_r($arr);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 2, Position 2 = 19
Branch analysis from position: 2
2 jumps found. (Code = 126) Position 1 = 3, Position 2 = 19
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/XOaFX
function name:  (null)
number of ops:  24
compiled vars:  !0 = $arr, !1 = $ar, !2 = $k, !3 = $mins
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   30     1      > FE_RESET_RW                                      $5      !0, ->19
          2    > > FE_FETCH_RW                                      ~6      $5, !1, ->19
          3    >   ASSIGN                                                   !2, ~6
   31     4        INIT_FCALL                                               'array_reduce'
          5        SEND_VAR                                                 !1
          6        DECLARE_LAMBDA_FUNCTION                          ~8      [0]
   35     7        SEND_VAL                                                 ~8
          8        SEND_VAL                                                 <array>
   31     9        DO_ICALL                                         $9      
         10        ASSIGN                                                   !3, $9
   36    11        INIT_FCALL                                               'array_filter'
         12        SEND_VAR                                                 !1
         13        DECLARE_LAMBDA_FUNCTION                          ~11     [1]
         14        BIND_LEXICAL                                             ~11, !3
   39    15        SEND_VAL                                                 ~11
   36    16        DO_ICALL                                         $12     
         17        ASSIGN                                                   !1, $12
   30    18      > JMP                                                      ->2
         19    >   FE_FREE                                                  $5
   41    20        INIT_FCALL                                               'print_r'
         21        SEND_VAR                                                 !0
         22        DO_ICALL                                                 
         23      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 17
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/XOaFX
function name:  {closure}
number of ops:  23
compiled vars:  !0 = $carry, !1 = $item, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   32     2        FETCH_DIM_R                                      ~3      !1, 'country'
          3        CONCAT                                           ~4      ~3, '%23%23%23'
          4        FETCH_DIM_R                                      ~5      !1, 'city'
          5        CONCAT                                           ~6      ~4, ~5
          6        ASSIGN                                                   !2, ~6
   33     7        ISSET_ISEMPTY_DIM_OBJ                         0  ~9      !0, !2
          8      > JMPZ_EX                                          ~9      ~9, ->13
          9    >   FETCH_DIM_R                                      ~10     !1, 'population'
         10        FETCH_DIM_R                                      ~11     !0, !2
         11        IS_SMALLER                                       ~12     ~11, ~10
         12        BOOL                                             ~9      ~12
         13    > > JMPZ                                                     ~9, ->17
         14    >   FETCH_DIM_R                                      ~13     !0, !2
         15        QM_ASSIGN                                        ~14     ~13
         16      > JMP                                                      ->19
         17    >   FETCH_DIM_R                                      ~15     !1, 'population'
         18        QM_ASSIGN                                        ~14     ~15
         19    >   ASSIGN_DIM                                               !0, !2
         20        OP_DATA                                                  ~14
   34    21      > RETURN                                                   !0
   35    22*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XOaFX
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $item, !1 = $mins, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   37     2        FETCH_DIM_R                                      ~3      !0, 'country'
          3        CONCAT                                           ~4      ~3, '%23%23%23'
          4        FETCH_DIM_R                                      ~5      !0, 'city'
          5        CONCAT                                           ~6      ~4, ~5
          6        ASSIGN                                                   !2, ~6
   38     7        FETCH_DIM_R                                      ~8      !1, !2
          8        FETCH_DIM_R                                      ~9      !0, 'population'
          9        IS_EQUAL                                         ~10     ~8, ~9
         10      > RETURN                                                   ~10
   39    11*     > RETURN                                                   null

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.07 ms | 1017 KiB | 16 Q