3v4l.org

run code in 300+ PHP versions simultaneously
<?php $students= array( array("name"=>"...", "gender"=>"male"), array("name"=>"...", "gender"=>"female"), array("name"=>"...", "gender"=>"female"), array("name"=>"...", "gender"=>"female"), array("name"=>"...", "gender"=>"male"), array("name"=>"...", "gender"=>"male"), array("name"=>"...", "gender"=>"male"), ); $males = array_values(array_filter($students, function($s) { return $s['gender'] === "male"; })); $females = array_values(array_filter($students, function($s) { return $s['gender'] === "female"; })); $final = array(); $max = max(count($females), count($males)); for ($i=0; $i<$max; $i++) { if (isset($males[$i])) { $final[] = $males[$i]; } if (isset($females[$i])) { $final[] = $females[$i]; } } print_r($final);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 29
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 34
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 39
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 29
Branch analysis from position: 42
Branch analysis from position: 29
Branch analysis from position: 39
Branch analysis from position: 34
filename:       /in/VVuBf
function name:  (null)
number of ops:  46
compiled vars:  !0 = $students, !1 = $males, !2 = $females, !3 = $final, !4 = $max, !5 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   13     1        INIT_FCALL                                               'array_values'
          2        INIT_FCALL                                               'array_filter'
          3        SEND_VAR                                                 !0
          4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FVVuBf%3A13%240'
          5        SEND_VAL                                                 ~7
          6        DO_ICALL                                         $8      
          7        SEND_VAR                                                 $8
          8        DO_ICALL                                         $9      
          9        ASSIGN                                                   !1, $9
   14    10        INIT_FCALL                                               'array_values'
         11        INIT_FCALL                                               'array_filter'
         12        SEND_VAR                                                 !0
         13        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FVVuBf%3A14%241'
         14        SEND_VAL                                                 ~11
         15        DO_ICALL                                         $12     
         16        SEND_VAR                                                 $12
         17        DO_ICALL                                         $13     
         18        ASSIGN                                                   !2, $13
   16    19        ASSIGN                                                   !3, <array>
   17    20        INIT_FCALL                                               'max'
         21        COUNT                                            ~16     !2
         22        SEND_VAL                                                 ~16
         23        COUNT                                            ~17     !1
         24        SEND_VAL                                                 ~17
         25        DO_ICALL                                         $18     
         26        ASSIGN                                                   !4, $18
   19    27        ASSIGN                                                   !5, 0
         28      > JMP                                                      ->40
   20    29    >   ISSET_ISEMPTY_DIM_OBJ                         0          !1, !5
         30      > JMPZ                                                     ~21, ->34
   21    31    >   FETCH_DIM_R                                      ~23     !1, !5
         32        ASSIGN_DIM                                               !3
         33        OP_DATA                                                  ~23
   24    34    >   ISSET_ISEMPTY_DIM_OBJ                         0          !2, !5
         35      > JMPZ                                                     ~24, ->39
   25    36    >   FETCH_DIM_R                                      ~26     !2, !5
         37        ASSIGN_DIM                                               !3
         38        OP_DATA                                                  ~26
   19    39    >   PRE_INC                                                  !5
         40    >   IS_SMALLER                                               !5, !4
         41      > JMPNZ                                                    ~28, ->29
   29    42    >   INIT_FCALL                                               'print_r'
         43        SEND_VAR                                                 !3
         44        DO_ICALL                                                 
         45      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FVVuBf%3A13%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VVuBf
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $s
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        FETCH_DIM_R                                      ~1      !0, 'gender'
          2        IS_IDENTICAL                                     ~2      ~1, 'male'
          3      > RETURN                                                   ~2
          4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FVVuBf%3A13%240

Function %00%7Bclosure%7D%2Fin%2FVVuBf%3A14%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VVuBf
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $s
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        FETCH_DIM_R                                      ~1      !0, 'gender'
          2        IS_IDENTICAL                                     ~2      ~1, 'female'
          3      > RETURN                                                   ~2
          4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FVVuBf%3A14%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.88 ms | 1400 KiB | 21 Q