3v4l.org

run code in 300+ PHP versions simultaneously
<?php $items = array( array ( 'title'=>"a", 'filename'=>"1.jpg" ), array ( 'title'=>"a", 'filename'=>"2.jpg" ), array ( 'title'=>"b", 'filename'=>"1.jpg" ), array ( 'title'=>"b", 'filename'=>"2.jpg" ) ); // I have used below to create an stdClass object array, don't use this line in your code $items = json_decode(json_encode($items)); $finalArray = []; foreach($items as $item){ $finalArray[$item->title]['filename'][] = $item->filename; } foreach($finalArray as $key=>$value){ echo $key.PHP_EOL; foreach($value['filename'] as $val){ echo $val.PHP_EOL; } echo PHP_EOL; echo PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 18
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 18
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 34
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 34
Branch analysis from position: 21
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 30
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 30
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 30
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
Branch analysis from position: 18
filename:       /in/DWrn1
function name:  (null)
number of ops:  36
compiled vars:  !0 = $items, !1 = $finalArray, !2 = $item, !3 = $value, !4 = $key, !5 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   22     1        INIT_FCALL                                               'json_decode'
          2        INIT_FCALL                                               'json_encode'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $7      
          5        SEND_VAR                                                 $7
          6        DO_ICALL                                         $8      
          7        ASSIGN                                                   !0, $8
   25     8        ASSIGN                                                   !1, <array>
   27     9      > FE_RESET_R                                       $11     !0, ->18
         10    > > FE_FETCH_R                                               $11, !2, ->18
   28    11    >   FETCH_OBJ_R                                      ~12     !2, 'title'
         12        FETCH_OBJ_R                                      ~16     !2, 'filename'
         13        FETCH_DIM_W                                      $13     !1, ~12
         14        FETCH_DIM_W                                      $14     $13, 'filename'
         15        ASSIGN_DIM                                               $14
         16        OP_DATA                                                  ~16
   27    17      > JMP                                                      ->10
         18    >   FE_FREE                                                  $11
   31    19      > FE_RESET_R                                       $17     !1, ->34
         20    > > FE_FETCH_R                                       ~18     $17, !3, ->34
         21    >   ASSIGN                                                   !4, ~18
   32    22        CONCAT                                           ~20     !4, '%0A'
         23        ECHO                                                     ~20
   33    24        FETCH_DIM_R                                      ~21     !3, 'filename'
         25      > FE_RESET_R                                       $22     ~21, ->30
         26    > > FE_FETCH_R                                               $22, !5, ->30
   34    27    >   CONCAT                                           ~23     !5, '%0A'
         28        ECHO                                                     ~23
   33    29      > JMP                                                      ->26
         30    >   FE_FREE                                                  $22
   36    31        ECHO                                                     '%0A'
   37    32        ECHO                                                     '%0A'
   31    33      > JMP                                                      ->20
         34    >   FE_FREE                                                  $17
   38    35      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.85 ms | 1400 KiB | 17 Q