3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = Array ( '3' => 10, '2' => 2, '5' => 'Nakiya', ); /** * Sort an array by key. */ function sortbyKeys($array, $direction = 'ASC') { $direction = (strtolower($direction) === 'desc') ? SORT_DESC : SORT_ASC; if ($direction === SORT_ASC) { ksort($array); } else { krsort($array); } return $array; } var_dump(sortbyKeys($array));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PXBi5
function name:  (null)
number of ops:  8
compiled vars:  !0 = $array
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   28     1        INIT_FCALL                                                   'var_dump'
          2        INIT_FCALL                                                   'sortbykeys'
          3        SEND_VAR                                                     !0
          4        DO_FCALL                                          0  $2      
          5        SEND_VAR                                                     $2
          6        DO_ICALL                                                     
          7      > RETURN                                                       1

Function sortbykeys:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
Branch analysis from position: 17
filename:       /in/PXBi5
function name:  sortbyKeys
number of ops:  22
compiled vars:  !0 = $array, !1 = $direction
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   15     0  E >   RECV                                                 !0      
          1        RECV_INIT                                            !1      'ASC'
   17     2        INIT_FCALL                                                   'strtolower'
          3        SEND_VAR                                                     !1
          4        DO_ICALL                                             $2      
          5        IS_IDENTICAL                                                 $2, 'desc'
          6      > JMPZ                                                         ~3, ->9
          7    >   QM_ASSIGN                                            ~4      3
          8      > JMP                                                          ->10
          9    >   QM_ASSIGN                                            ~4      4
         10    >   ASSIGN                                                       !1, ~4
   18    11        IS_IDENTICAL                                                 !1, 4
         12      > JMPZ                                                         ~6, ->17
   19    13    >   INIT_FCALL                                                   'ksort'
         14        SEND_REF                                                     !0
         15        DO_ICALL                                                     
   18    16      > JMP                                                          ->20
   21    17    >   INIT_FCALL                                                   'krsort'
         18        SEND_REF                                                     !0
         19        DO_ICALL                                                     
   24    20    > > RETURN                                                       !0
   25    21*     > RETURN                                                       null

End of function sortbykeys

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
165.89 ms | 2115 KiB | 18 Q