3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array ('Q1 2017'=>'some value', 'Q3 2017'=>'some value', 'Q3 2012'=>'some value', 'Q4 2015'=>'some value', 'Q4 2017'=>'some value', 'Q2 2017'=>'some value'); $new = array(); foreach($arr as $key=>$subarr){ $tempArr = explode(' ', $key); $new[$tempArr[1]][$tempArr[0]] = $subarr; asort($new[$tempArr[1]]); } ksort($new); $secondarr = array(); foreach($new as $k=>$v){ ksort($v); $secondarr[$k] = $v; } foreach($secondarr as $key => $val){ foreach($val as $k=>$v){ $newkey = $k.' '.$key; $finalarr[$newkey] = $v; } } echo "<pre>"; print_r($finalarr);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 21
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 21
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 21
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 35
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 35
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 35
2 jumps found. (Code = 77) Position 1 = 37, Position 2 = 50
Branch analysis from position: 37
2 jumps found. (Code = 78) Position 1 = 38, Position 2 = 50
Branch analysis from position: 38
2 jumps found. (Code = 77) Position 1 = 40, Position 2 = 48
Branch analysis from position: 40
2 jumps found. (Code = 78) Position 1 = 41, Position 2 = 48
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 48
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
Branch analysis from position: 35
Branch analysis from position: 21
filename:       /in/ajAa0
function name:  (null)
number of ops:  56
compiled vars:  !0 = $arr, !1 = $new, !2 = $subarr, !3 = $key, !4 = $tempArr, !5 = $secondarr, !6 = $v, !7 = $k, !8 = $val, !9 = $newkey, !10 = $finalarr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    6     1        ASSIGN                                                   !1, <array>
    7     2      > FE_RESET_R                                       $13     !0, ->21
          3    > > FE_FETCH_R                                       ~14     $13, !2, ->21
          4    >   ASSIGN                                                   !3, ~14
    8     5        INIT_FCALL                                               'explode'
          6        SEND_VAL                                                 '+'
          7        SEND_VAR                                                 !3
          8        DO_ICALL                                         $16     
          9        ASSIGN                                                   !4, $16
    9    10        FETCH_DIM_R                                      ~18     !4, 1
         11        FETCH_DIM_R                                      ~20     !4, 0
         12        FETCH_DIM_W                                      $19     !1, ~18
         13        ASSIGN_DIM                                               $19, ~20
         14        OP_DATA                                                  !2
   10    15        INIT_FCALL                                               'asort'
         16        FETCH_DIM_R                                      ~22     !4, 1
         17        FETCH_DIM_W                                      $23     !1, ~22
         18        SEND_REF                                                 $23
         19        DO_ICALL                                                 
    7    20      > JMP                                                      ->3
         21    >   FE_FREE                                                  $13
   13    22        INIT_FCALL                                               'ksort'
         23        SEND_REF                                                 !1
         24        DO_ICALL                                                 
   14    25        ASSIGN                                                   !5, <array>
   15    26      > FE_RESET_R                                       $27     !1, ->35
         27    > > FE_FETCH_R                                       ~28     $27, !6, ->35
         28    >   ASSIGN                                                   !7, ~28
   16    29        INIT_FCALL                                               'ksort'
         30        SEND_REF                                                 !6
         31        DO_ICALL                                                 
   17    32        ASSIGN_DIM                                               !5, !7
         33        OP_DATA                                                  !6
   15    34      > JMP                                                      ->27
         35    >   FE_FREE                                                  $27
   20    36      > FE_RESET_R                                       $32     !5, ->50
         37    > > FE_FETCH_R                                       ~33     $32, !8, ->50
         38    >   ASSIGN                                                   !3, ~33
   21    39      > FE_RESET_R                                       $35     !8, ->48
         40    > > FE_FETCH_R                                       ~36     $35, !6, ->48
         41    >   ASSIGN                                                   !7, ~36
   22    42        CONCAT                                           ~38     !7, '+'
         43        CONCAT                                           ~39     ~38, !3
         44        ASSIGN                                                   !9, ~39
   23    45        ASSIGN_DIM                                               !10, !9
         46        OP_DATA                                                  !6
   21    47      > JMP                                                      ->40
         48    >   FE_FREE                                                  $35
   20    49      > JMP                                                      ->37
         50    >   FE_FREE                                                  $32
   27    51        ECHO                                                     '%3Cpre%3E'
         52        INIT_FCALL                                               'print_r'
         53        SEND_VAR                                                 !10
         54        DO_ICALL                                                 
         55      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
131.28 ms | 1405 KiB | 21 Q