3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = array( 0 => array( "label"=>"Ai", "male"=>0, "female"=>10 ), 1=> array( "label"=>"Bi", "male"=>0, "female"=>20 ), 2=> array( "label"=>"Ci", "male"=>10, "female"=>20 ) ); function getMinMaxFromArray($array,$type,$columnToChoseForMinMax){ if($type =='min'){ $min = min(array_column($array,$columnToChoseForMinMax)); $keys = array_keys(array_column($array,$columnToChoseForMinMax), $min); } if($type =='max'){ $max = max(array_column($array,$columnToChoseForMinMax)); $keys = array_keys(array_column($array,$columnToChoseForMinMax), $max); } $finalArray =[]; foreach($keys as $key){ $finalArray[] = array( 'label'=>$array[$key]['label'], 'male'=>$array[$key]['male'] ); } return $finalArray; } print_r(getMinMaxFromArray($array,'min','male')); print_r(getMinMaxFromArray($array,'max','male')); print_r(getMinMaxFromArray($array,'min','female')); print_r(getMinMaxFromArray($array,'max','female'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/E38gV
function name:  (null)
number of ops:  34
compiled vars:  !0 = $array
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   47     1        INIT_FCALL                                                   'print_r'
          2        INIT_FCALL                                                   'getminmaxfromarray'
          3        SEND_VAR                                                     !0
          4        SEND_VAL                                                     'min'
          5        SEND_VAL                                                     'male'
          6        DO_FCALL                                          0  $2      
          7        SEND_VAR                                                     $2
          8        DO_ICALL                                                     
   48     9        INIT_FCALL                                                   'print_r'
         10        INIT_FCALL                                                   'getminmaxfromarray'
         11        SEND_VAR                                                     !0
         12        SEND_VAL                                                     'max'
         13        SEND_VAL                                                     'male'
         14        DO_FCALL                                          0  $4      
         15        SEND_VAR                                                     $4
         16        DO_ICALL                                                     
   50    17        INIT_FCALL                                                   'print_r'
         18        INIT_FCALL                                                   'getminmaxfromarray'
         19        SEND_VAR                                                     !0
         20        SEND_VAL                                                     'min'
         21        SEND_VAL                                                     'female'
         22        DO_FCALL                                          0  $6      
         23        SEND_VAR                                                     $6
         24        DO_ICALL                                                     
   51    25        INIT_FCALL                                                   'print_r'
         26        INIT_FCALL                                                   'getminmaxfromarray'
         27        SEND_VAR                                                     !0
         28        SEND_VAL                                                     'max'
         29        SEND_VAL                                                     'female'
         30        DO_FCALL                                          0  $8      
         31        SEND_VAR                                                     $8
         32        DO_ICALL                                                     
         33      > RETURN                                                       1

Function getminmaxfromarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 22
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 41
Branch analysis from position: 24
2 jumps found. (Code = 77) Position 1 = 43, Position 2 = 53
Branch analysis from position: 43
2 jumps found. (Code = 78) Position 1 = 44, Position 2 = 53
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
Branch analysis from position: 41
Branch analysis from position: 22
filename:       /in/E38gV
function name:  getMinMaxFromArray
number of ops:  56
compiled vars:  !0 = $array, !1 = $type, !2 = $columnToChoseForMinMax, !3 = $min, !4 = $keys, !5 = $max, !6 = $finalArray, !7 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   22     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
   24     3        IS_EQUAL                                                     !1, 'min'
          4      > JMPZ                                                         ~8, ->22
   25     5    >   INIT_FCALL                                                   'min'
          6        INIT_FCALL                                                   'array_column'
          7        SEND_VAR                                                     !0
          8        SEND_VAR                                                     !2
          9        DO_ICALL                                             $9      
         10        SEND_VAR                                                     $9
         11        DO_ICALL                                             $10     
         12        ASSIGN                                                       !3, $10
   27    13        INIT_FCALL                                                   'array_keys'
         14        INIT_FCALL                                                   'array_column'
         15        SEND_VAR                                                     !0
         16        SEND_VAR                                                     !2
         17        DO_ICALL                                             $12     
         18        SEND_VAR                                                     $12
         19        SEND_VAR                                                     !3
         20        DO_ICALL                                             $13     
         21        ASSIGN                                                       !4, $13
   30    22    >   IS_EQUAL                                                     !1, 'max'
         23      > JMPZ                                                         ~15, ->41
   32    24    >   INIT_FCALL                                                   'max'
         25        INIT_FCALL                                                   'array_column'
         26        SEND_VAR                                                     !0
         27        SEND_VAR                                                     !2
         28        DO_ICALL                                             $16     
         29        SEND_VAR                                                     $16
         30        DO_ICALL                                             $17     
         31        ASSIGN                                                       !5, $17
   34    32        INIT_FCALL                                                   'array_keys'
         33        INIT_FCALL                                                   'array_column'
         34        SEND_VAR                                                     !0
         35        SEND_VAR                                                     !2
         36        DO_ICALL                                             $19     
         37        SEND_VAR                                                     $19
         38        SEND_VAR                                                     !5
         39        DO_ICALL                                             $20     
         40        ASSIGN                                                       !4, $20
   36    41    >   ASSIGN                                                       !6, <array>
   37    42      > FE_RESET_R                                           $23     !4, ->53
         43    > > FE_FETCH_R                                                   $23, !7, ->53
   39    44    >   FETCH_DIM_R                                          ~25     !0, !7
         45        FETCH_DIM_R                                          ~26     ~25, 'label'
         46        INIT_ARRAY                                           ~27     ~26, 'label'
   40    47        FETCH_DIM_R                                          ~28     !0, !7
         48        FETCH_DIM_R                                          ~29     ~28, 'male'
         49        ADD_ARRAY_ELEMENT                                    ~27     ~29, 'male'
   38    50        ASSIGN_DIM                                                   !6
   40    51        OP_DATA                                                      ~27
   37    52      > JMP                                                          ->43
         53    >   FE_FREE                                                      $23
   44    54      > RETURN                                                       !6
   45    55*     > RETURN                                                       null

End of function getminmaxfromarray

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
171.51 ms | 2231 KiB | 22 Q