3v4l.org

run code in 300+ PHP versions simultaneously
<?php $abc = array( 'rec_1' => array('fn'=>'Aron','ln'=>'Michaels'), 'rec_2' => array('fn'=>'Abbey','ln'=>'Drake'), 'rec_3' => array('fn'=>'Alice','ln'=>'Peterson')); /*function build_sorter($key) { return function ($a, $b) use ($key) { return strcmp($a[$key], $b[$key]); }; }*/ function sortit($a, $b , $key) { return strcmp($a[$key], $b[$key]); }; function mysort($key) { return sortit($a,$b,$key); } //usort($abc, build_sorter('ln')); usort($abc, mysort('ln')); foreach ($abc as $item) { echo strtoupper($item['ln']) . ', ' . $item['fn'] . "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 20
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 20
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/tDvVM
function name:  (null)
number of ops:  22
compiled vars:  !0 = $abc, !1 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   27     1        INIT_FCALL                                               'usort'
          2        SEND_REF                                                 !0
          3        INIT_FCALL                                               'mysort'
          4        SEND_VAL                                                 'ln'
          5        DO_FCALL                                      0  $3      
          6        SEND_VAR                                                 $3
          7        DO_ICALL                                                 
   29     8      > FE_RESET_R                                       $5      !0, ->20
          9    > > FE_FETCH_R                                               $5, !1, ->20
   30    10    >   INIT_FCALL                                               'strtoupper'
         11        FETCH_DIM_R                                      ~6      !1, 'ln'
         12        SEND_VAL                                                 ~6
         13        DO_ICALL                                         $7      
         14        CONCAT                                           ~8      $7, '%2C+'
         15        FETCH_DIM_R                                      ~9      !1, 'fn'
         16        CONCAT                                           ~10     ~8, ~9
         17        CONCAT                                           ~11     ~10, '%0A'
         18        ECHO                                                     ~11
   29    19      > JMP                                                      ->9
         20    >   FE_FREE                                                  $5
   31    21      > RETURN                                                   1

Function sortit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tDvVM
function name:  sortit
number of ops:  11
compiled vars:  !0 = $a, !1 = $b, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   15     3        INIT_FCALL                                               'strcmp'
          4        FETCH_DIM_R                                      ~3      !0, !2
          5        SEND_VAL                                                 ~3
          6        FETCH_DIM_R                                      ~4      !1, !2
          7        SEND_VAL                                                 ~4
          8        DO_ICALL                                         $5      
          9      > RETURN                                                   $5
   16    10*     > RETURN                                                   null

End of function sortit

Function mysort:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tDvVM
function name:  mysort
number of ops:  8
compiled vars:  !0 = $key, !1 = $a, !2 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   20     1        INIT_FCALL                                               'sortit'
          2        SEND_VAR                                                 !1
          3        SEND_VAR                                                 !2
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $3      
          6      > RETURN                                                   $3
   21     7*     > RETURN                                                   null

End of function mysort

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.44 ms | 1394 KiB | 21 Q