3v4l.org

run code in 500+ PHP versions simultaneously
<?php $data = [["label" => "Ai", "male" => 0, "female"=>10, ], ["label" => "Bi", "male" => 0, "female"=>20, ], ["label" => "Ci", "male" => 10, "female"=>20, ],]; //$minmax = 'min'; //$gen = 'male'; function getMinMaxGen($data,$minmax,$gen){ $res = ['value' => 0,'sets' => []]; if(in_array($minmax,['min','max'])){ $arcol = array_column($data,$gen); $res['value'] = $minmax($arcol); } if(in_array($gen,['male','female'])){ foreach($data as $person){ if ($person[$gen] === $res['value']) $res['sets'][] = ['label' => $person['label'], "$gen" => $person[$gen]]; } } return $res; } $result = getMinMaxGen($data,'max','female'); print_r($result); //print_r(getMinMaxGen($data,'min','female')); //print_r(getMinMaxGen($data,'max','male')); //print_r(getMinMaxGen($data,'min','male'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/E330t
function name:  (null)
number of ops:  11
compiled vars:  !0 = $data, !1 = $result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   24     1        INIT_FCALL                                                   'getminmaxgen'
          2        SEND_VAR                                                     !0
          3        SEND_VAL                                                     'max'
          4        SEND_VAL                                                     'female'
          5        DO_FCALL                                          0  $3      
          6        ASSIGN                                                       !1, $3
   25     7        INIT_FCALL                                                   'print_r'
          8        SEND_VAR                                                     !1
          9        DO_ICALL                                                     
   28    10      > RETURN                                                       1

Function getminmaxgen:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 16
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 34
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 33
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 33
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 32
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 32
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
Branch analysis from position: 34
Branch analysis from position: 16
filename:       /in/E330t
function name:  getMinMaxGen
number of ops:  36
compiled vars:  !0 = $data, !1 = $minmax, !2 = $gen, !3 = $res, !4 = $arcol, !5 = $person
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
    9     3        ASSIGN                                                       !3, <array>
   11     4        IN_ARRAY                                                     !1, <array>
          5      > JMPZ                                                         ~7, ->16
   12     6    >   INIT_FCALL                                                   'array_column'
          7        SEND_VAR                                                     !0
          8        SEND_VAR                                                     !2
          9        DO_ICALL                                             $8      
         10        ASSIGN                                                       !4, $8
   13    11        INIT_DYNAMIC_CALL                                            !1
         12        SEND_VAR_EX                                                  !4
         13        DO_FCALL                                          0  $11     
         14        ASSIGN_DIM                                                   !3, 'value'
         15        OP_DATA                                                      $11
   16    16    >   IN_ARRAY                                                     !2, <array>
         17      > JMPZ                                                         ~12, ->34
   17    18    > > FE_RESET_R                                           $13     !0, ->33
         19    > > FE_FETCH_R                                                   $13, !5, ->33
   18    20    >   FETCH_DIM_R                                          ~14     !5, !2
         21        FETCH_DIM_R                                          ~15     !3, 'value'
         22        IS_IDENTICAL                                                 ~14, ~15
         23      > JMPZ                                                         ~16, ->32
         24    >   FETCH_DIM_R                                          ~19     !5, 'label'
         25        INIT_ARRAY                                           ~20     ~19, 'label'
         26        CAST                                              6  ~21     !2
         27        FETCH_DIM_R                                          ~22     !5, !2
         28        ADD_ARRAY_ELEMENT                                    ~20     ~22, ~21
         29        FETCH_DIM_W                                          $17     !3, 'sets'
         30        ASSIGN_DIM                                                   $17
         31        OP_DATA                                                      ~20
   17    32    > > JMP                                                          ->19
         33    >   FE_FREE                                                      $13
   21    34    > > RETURN                                                       !3
   22    35*     > RETURN                                                       null

End of function getminmaxgen

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
178.2 ms | 2223 KiB | 16 Q