3v4l.org

run code in 500+ 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 = 37
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 26
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 31
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 36
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 26
Branch analysis from position: 39
Branch analysis from position: 26
Branch analysis from position: 36
Branch analysis from position: 31
filename:       /in/VVuBf
function name:  (null)
number of ops:  43
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                              ~7      [0]
          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                              ~11     [1]
         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        COUNT                                                ~16     !2
         21        COUNT                                                ~17     !1
         22        FRAMELESS_ICALL_2                max                 ~18     ~16, ~17
         23        ASSIGN                                                       !4, ~18
   19    24        ASSIGN                                                       !5, 0
         25      > JMP                                                          ->37
   20    26    >   ISSET_ISEMPTY_DIM_OBJ                             0          !1, !5
         27      > JMPZ                                                         ~21, ->31
   21    28    >   FETCH_DIM_R                                          ~23     !1, !5
         29        ASSIGN_DIM                                                   !3
         30        OP_DATA                                                      ~23
   24    31    >   ISSET_ISEMPTY_DIM_OBJ                             0          !2, !5
         32      > JMPZ                                                         ~24, ->36
   25    33    >   FETCH_DIM_R                                          ~26     !2, !5
         34        ASSIGN_DIM                                                   !3
         35        OP_DATA                                                      ~26
   19    36    >   PRE_INC                                                      !5
         37    >   IS_SMALLER                                                   !5, !4
         38      > JMPNZ                                                        ~28, ->26
   29    39    >   INIT_FCALL                                                   'print_r'
         40        SEND_VAR                                                     !3
         41        DO_ICALL                                                     
         42      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VVuBf
function name:  {closure:/in/VVuBf:13}
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 Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VVuBf
function name:  {closure:/in/VVuBf:14}
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 Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
205.04 ms | 2519 KiB | 16 Q