3v4l.org

run code in 300+ PHP versions simultaneously
<?php $test = ['Red orange 2016','orange 2017' ,'Mango 2018' ,'Granny Smith apple 2018' ,'apple 2015']; $a = array(); // create two new arrays to hold fruit and year $b = array(); $temp = array(); foreach($test as $item){ $temp = explode(" ", $item); // explode the fruit/year to temp array $a[] = implode(" ", array_splice($temp, 0, -1)); // implode all but the last item as "fruit" $b[] = end($temp); // last item is the year } array_multisort($b, $a); // sort the new arrays $result=array(); for($i=count($b)-1; $i>=0; $i--){ // looping backwards to only count() once. (faster) $result[] = $a[$i] . " " . $b[$i]; // rebuild the new array with correct sorting. } var_dump($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 28
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 28
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 38
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 38
Branch analysis from position: 47
Branch analysis from position: 38
Branch analysis from position: 28
filename:       /in/eCi7J
function name:  (null)
number of ops:  51
compiled vars:  !0 = $test, !1 = $a, !2 = $b, !3 = $temp, !4 = $item, !5 = $result, !6 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    5     1        ASSIGN                                                   !1, <array>
    6     2        ASSIGN                                                   !2, <array>
    7     3        ASSIGN                                                   !3, <array>
    8     4      > FE_RESET_R                                       $11     !0, ->28
          5    > > FE_FETCH_R                                               $11, !4, ->28
    9     6    >   INIT_FCALL                                               'explode'
          7        SEND_VAL                                                 '+'
          8        SEND_VAR                                                 !4
          9        DO_ICALL                                         $12     
         10        ASSIGN                                                   !3, $12
   10    11        INIT_FCALL                                               'implode'
         12        SEND_VAL                                                 '+'
         13        INIT_FCALL                                               'array_splice'
         14        SEND_REF                                                 !3
         15        SEND_VAL                                                 0
         16        SEND_VAL                                                 -1
         17        DO_ICALL                                         $15     
         18        SEND_VAR                                                 $15
         19        DO_ICALL                                         $16     
         20        ASSIGN_DIM                                               !1
         21        OP_DATA                                                  $16
   11    22        INIT_FCALL                                               'end'
         23        SEND_REF                                                 !3
         24        DO_ICALL                                         $18     
         25        ASSIGN_DIM                                               !2
         26        OP_DATA                                                  $18
    8    27      > JMP                                                      ->5
         28    >   FE_FREE                                                  $11
   14    29        INIT_FCALL                                               'array_multisort'
         30        SEND_REF                                                 !2
         31        SEND_REF                                                 !1
         32        DO_ICALL                                                 
   16    33        ASSIGN                                                   !5, <array>
   17    34        COUNT                                            ~21     !2
         35        SUB                                              ~22     ~21, 1
         36        ASSIGN                                                   !6, ~22
         37      > JMP                                                      ->45
   18    38    >   FETCH_DIM_R                                      ~25     !1, !6
         39        CONCAT                                           ~26     ~25, '+'
         40        FETCH_DIM_R                                      ~27     !2, !6
         41        CONCAT                                           ~28     ~26, ~27
         42        ASSIGN_DIM                                               !5
         43        OP_DATA                                                  ~28
   17    44        PRE_DEC                                                  !6
         45    >   IS_SMALLER_OR_EQUAL                                      0, !6
         46      > JMPNZ                                                    ~30, ->38
   20    47    >   INIT_FCALL                                               'var_dump'
         48        SEND_VAR                                                 !5
         49        DO_ICALL                                                 
         50      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.96 ms | 1447 KiB | 19 Q