3v4l.org

run code in 500+ PHP versions simultaneously
<?php /* Groups passed arrays in an array of associative arrays with same keys and values * * @example $array1 = array( array('a'=>'val1'),array('a'=>'val2') ); * $array2 = array( array('b'=>'val3'),array('b'=>'val4') ); * $array3 = array( array('c'=>'val5'),array(),array('c'=>'val6') ); * multiArrayCombine( $array1, $array2, $array3 ); * return: array * ( * 0 => array('a'=>'val1','b'=>'val3','c'=>'val5'), * 1 => array('a'=>'val2','b'=>'val4'), * 2 => array('c'=>'val6') * ) * * @param array $array1[, $array2[, $array3...]] * * @option const T_OBJECT_CAST cast returned assoc arrays as stdObject * * @return array */ function multiArrayCombine() { /* Get all passed parameters and T_OBJECT_CAST option: */ $args = func_get_args(); $asObject = ( T_OBJECT_CAST == end($args) ); if( $asObject ) array_pop( $args ); $retval = array(); # Init array to be returned /* Retrieve highest passed arrays key: */ $max = 0; foreach( $args as $array ) $max = max( $max, max( array_keys($array) ) ); /* Loop for each arrays key: */ for( $i=0; $i<=$max; $i++ ) { /* Init associative array to add: */ $add = array(); /* Process actual key ($i) of each passed array: */ foreach( $args as $array ) { /* If the key ($i) exists, add each passed array: */ if( isset($array[$i]) AND is_array($array[$i]) ) { foreach( $array[$i] as $key => $val ) { $add[$key] = $val; } } } /* Add the obtained associative array to return array */ if( $asObject ) $retval[] = (object) $add; else $retval[] = $add; } return $retval; } $array1 = array( array('accordion_title'=>'Title 1'),array('accordion_title'=>'Title 2') ); $array2 = array( array('accordion_content'=>'Content 1'),array('accordion_content'=>'Content 2') ); $array3 = array( array('accordion_date'=>'Date 1'),array(),array('accordion_date'=>'Date 3') ); print_r( multiArrayCombine( $array1, $array2, $array3 ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KFVp1
function name:  (null)
number of ops:  12
compiled vars:  !0 = $array1, !1 = $array2, !2 = $array3
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   60     0  E >   ASSIGN                                                       !0, <array>
   61     1        ASSIGN                                                       !1, <array>
   62     2        ASSIGN                                                       !2, <array>
   64     3        INIT_FCALL                                                   'print_r'
          4        INIT_FCALL                                                   'multiarraycombine'
          5        SEND_VAR                                                     !0
          6        SEND_VAR                                                     !1
          7        SEND_VAR                                                     !2
          8        DO_FCALL                                          0  $6      
          9        SEND_VAR                                                     $6
         10        DO_ICALL                                                     
         11      > RETURN                                                       1

Function multiarraycombine:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 24
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 24
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
2 jumps found. (Code = 44) Position 1 = 56, Position 2 = 27
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
2 jumps found. (Code = 77) Position 1 = 29, Position 2 = 45
Branch analysis from position: 29
2 jumps found. (Code = 78) Position 1 = 30, Position 2 = 45
Branch analysis from position: 30
2 jumps found. (Code = 46) Position 1 = 32, Position 2 = 35
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 44
Branch analysis from position: 36
2 jumps found. (Code = 77) Position 1 = 38, Position 2 = 43
Branch analysis from position: 38
2 jumps found. (Code = 78) Position 1 = 39, Position 2 = 43
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Branch analysis from position: 43
Branch analysis from position: 44
Branch analysis from position: 35
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 51
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
2 jumps found. (Code = 44) Position 1 = 56, Position 2 = 27
Branch analysis from position: 56
Branch analysis from position: 27
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 56, Position 2 = 27
Branch analysis from position: 56
Branch analysis from position: 27
Branch analysis from position: 45
Branch analysis from position: 24
Branch analysis from position: 11
filename:       /in/KFVp1
function name:  multiArrayCombine
number of ops:  58
compiled vars:  !0 = $args, !1 = $asObject, !2 = $retval, !3 = $max, !4 = $array, !5 = $i, !6 = $add, !7 = $val, !8 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   25     0  E >   FUNC_GET_ARGS                                        ~9      
          1        ASSIGN                                                       !0, ~9
   26     2        INIT_FCALL                                                   'end'
          3        SEND_REF                                                     !0
          4        DO_ICALL                                             $11     
          5        IS_EQUAL                                             ~12     $11, 385
          6        ASSIGN                                                       !1, ~12
   27     7      > JMPZ                                                         !1, ->11
          8    >   INIT_FCALL                                                   'array_pop'
          9        SEND_REF                                                     !0
         10        DO_ICALL                                                     
   29    11    >   ASSIGN                                                       !2, <array>
   32    12        ASSIGN                                                       !3, 0
   33    13      > FE_RESET_R                                           $17     !0, ->24
         14    > > FE_FETCH_R                                                   $17, !4, ->24
         15    >   INIT_FCALL                                                   'max'
         16        INIT_FCALL                                                   'array_keys'
         17        SEND_VAR                                                     !4
         18        DO_ICALL                                             $18     
         19        SEND_VAR                                                     $18
         20        DO_ICALL                                             $19     
         21        FRAMELESS_ICALL_2                max                 ~20     !3, $19
         22        ASSIGN                                                       !3, ~20
         23      > JMP                                                          ->14
         24    >   FE_FREE                                                      $17
   36    25        ASSIGN                                                       !5, 0
         26      > JMP                                                          ->54
   39    27    >   ASSIGN                                                       !6, <array>
   42    28      > FE_RESET_R                                           $24     !0, ->45
         29    > > FE_FETCH_R                                                   $24, !4, ->45
   45    30    >   ISSET_ISEMPTY_DIM_OBJ                             0  ~25     !4, !5
         31      > JMPZ_EX                                              ~25     ~25, ->35
         32    >   FETCH_DIM_R                                          ~26     !4, !5
         33        TYPE_CHECK                                      128  ~27     ~26
         34        BOOL                                                 ~25     ~27
         35    > > JMPZ                                                         ~25, ->44
   47    36    >   FETCH_DIM_R                                          ~28     !4, !5
         37      > FE_RESET_R                                           $29     ~28, ->43
         38    > > FE_FETCH_R                                           ~30     $29, !7, ->43
         39    >   ASSIGN                                                       !8, ~30
   48    40        ASSIGN_DIM                                                   !6, !8
         41        OP_DATA                                                      !7
   47    42      > JMP                                                          ->38
         43    >   FE_FREE                                                      $29
   42    44    > > JMP                                                          ->29
         45    >   FE_FREE                                                      $24
   53    46      > JMPZ                                                         !1, ->51
         47    >   CAST                                              8  ~34     !6
         48        ASSIGN_DIM                                                   !2
         49        OP_DATA                                                      ~34
         50      > JMP                                                          ->53
   54    51    >   ASSIGN_DIM                                                   !2
         52        OP_DATA                                                      !6
   36    53    >   PRE_INC                                                      !5
         54    >   IS_SMALLER_OR_EQUAL                                          !5, !3
         55      > JMPNZ                                                        ~37, ->27
   57    56    > > RETURN                                                       !2
   58    57*     > RETURN                                                       null

End of function multiarraycombine

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
213.86 ms | 1893 KiB | 19 Q