3v4l.org

run code in 300+ 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 = 27
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 27
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
2 jumps found. (Code = 44) Position 1 = 59, Position 2 = 30
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
2 jumps found. (Code = 77) Position 1 = 32, Position 2 = 48
Branch analysis from position: 32
2 jumps found. (Code = 78) Position 1 = 33, Position 2 = 48
Branch analysis from position: 33
2 jumps found. (Code = 46) Position 1 = 35, Position 2 = 38
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 47
Branch analysis from position: 39
2 jumps found. (Code = 77) Position 1 = 41, Position 2 = 46
Branch analysis from position: 41
2 jumps found. (Code = 78) Position 1 = 42, Position 2 = 46
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 46
Branch analysis from position: 47
Branch analysis from position: 38
Branch analysis from position: 48
2 jumps found. (Code = 43) Position 1 = 50, Position 2 = 54
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
2 jumps found. (Code = 44) Position 1 = 59, Position 2 = 30
Branch analysis from position: 59
Branch analysis from position: 30
Branch analysis from position: 54
2 jumps found. (Code = 44) Position 1 = 59, Position 2 = 30
Branch analysis from position: 59
Branch analysis from position: 30
Branch analysis from position: 48
Branch analysis from position: 27
Branch analysis from position: 11
filename:       /in/KFVp1
function name:  multiArrayCombine
number of ops:  61
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, 303
          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, ->27
         14    > > FE_FETCH_R                                               $17, !4, ->27
         15    >   INIT_FCALL                                               'max'
         16        SEND_VAR                                                 !3
         17        INIT_FCALL                                               'max'
         18        INIT_FCALL                                               'array_keys'
         19        SEND_VAR                                                 !4
         20        DO_ICALL                                         $18     
         21        SEND_VAR                                                 $18
         22        DO_ICALL                                         $19     
         23        SEND_VAR                                                 $19
         24        DO_ICALL                                         $20     
         25        ASSIGN                                                   !3, $20
         26      > JMP                                                      ->14
         27    >   FE_FREE                                                  $17
   36    28        ASSIGN                                                   !5, 0
         29      > JMP                                                      ->57
   39    30    >   ASSIGN                                                   !6, <array>
   42    31      > FE_RESET_R                                       $24     !0, ->48
         32    > > FE_FETCH_R                                               $24, !4, ->48
   45    33    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~25     !4, !5
         34      > JMPZ_EX                                          ~25     ~25, ->38
         35    >   FETCH_DIM_R                                      ~26     !4, !5
         36        TYPE_CHECK                                  128  ~27     ~26
         37        BOOL                                             ~25     ~27
         38    > > JMPZ                                                     ~25, ->47
   47    39    >   FETCH_DIM_R                                      ~28     !4, !5
         40      > FE_RESET_R                                       $29     ~28, ->46
         41    > > FE_FETCH_R                                       ~30     $29, !7, ->46
         42    >   ASSIGN                                                   !8, ~30
   48    43        ASSIGN_DIM                                               !6, !8
         44        OP_DATA                                                  !7
   47    45      > JMP                                                      ->41
         46    >   FE_FREE                                                  $29
   42    47    > > JMP                                                      ->32
         48    >   FE_FREE                                                  $24
   53    49      > JMPZ                                                     !1, ->54
         50    >   CAST                                          8  ~34     !6
         51        ASSIGN_DIM                                               !2
         52        OP_DATA                                                  ~34
         53      > JMP                                                      ->56
   54    54    >   ASSIGN_DIM                                               !2
         55        OP_DATA                                                  !6
   36    56    >   PRE_INC                                                  !5
         57    >   IS_SMALLER_OR_EQUAL                                      !5, !3
         58      > JMPNZ                                                    ~37, ->30
   57    59    > > RETURN                                                   !2
   58    60*     > RETURN                                                   null

End of function multiarraycombine

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.88 ms | 1018 KiB | 19 Q