3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['name'=>'Strawberry','id'=>'10'], ['id'=>'13'], ['name'=>'Apple','id'=>'20'], ['id'=>'28'], ['name'=>'Mandarin','id'=>'30'], ['name'=>'Apple','id'=>'50'], ['name'=>'Strawberry','id'=>'60'], ]; $tmp_arr = []; foreach( $array as $element ) { if( array_key_exists('name', $element) ) { $tmp_arr[$element['name']][] = $element; } else { $tmp_arr[] = [$element]; } } var_dump($tmp_arr); $array = call_user_func_array('array_merge', $tmp_arr); var_dump($array);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 15
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/BS6Jc
function name:  (null)
number of ops:  28
compiled vars:  !0 = $array, !1 = $tmp_arr, !2 = $element
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   12     1        ASSIGN                                                   !1, <array>
   13     2      > FE_RESET_R                                       $5      !0, ->15
          3    > > FE_FETCH_R                                               $5, !2, ->15
   14     4    >   ARRAY_KEY_EXISTS                                         'name', !2
          5      > JMPZ                                                     ~6, ->11
   16     6    >   FETCH_DIM_R                                      ~7      !2, 'name'
          7        FETCH_DIM_W                                      $8      !1, ~7
          8        ASSIGN_DIM                                               $8
          9        OP_DATA                                                  !2
   14    10      > JMP                                                      ->14
   19    11    >   INIT_ARRAY                                       ~11     !2
         12        ASSIGN_DIM                                               !1
         13        OP_DATA                                                  ~11
   13    14    > > JMP                                                      ->3
         15    >   FE_FREE                                                  $5
   22    16        INIT_FCALL                                               'var_dump'
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                                 
   24    19        INIT_FCALL                                               'array_merge'
         20        SEND_ARRAY                                               !1
         21        CHECK_UNDEF_ARGS                                         
         22        DO_FCALL                                      1  $13     
         23        ASSIGN                                                   !0, $13
   25    24        INIT_FCALL                                               'var_dump'
         25        SEND_VAR                                                 !0
         26        DO_ICALL                                                 
         27      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
179.12 ms | 1000 KiB | 15 Q