3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Raw data $json = <<<'JSON' { "player1": { "money": 1000, "kills": 6 }, "player2": { "money": 3000, "kills": 12 }, "player3": { "money": 2000, "kills": 2 } } JSON; // Prepare $sortBy = 'money'; $order = 'desc'; $dataset = json_decode($json, true); // Sorting usort($dataset, fn (array $playerA, array $playerB): int => ($playerA['money'] > $playerB['money'] ? -1 : 1) * ['desc' => 1, 'asc' => -1][$order] ?? -1); // Print results var_dump($dataset);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iZc0p
function name:  (null)
number of ops:  18
compiled vars:  !0 = $json, !1 = $sortBy, !2 = $order, !3 = $dataset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, '%7B%0A++++%22player1%22%3A+%7B%0A++++++++%22money%22%3A+1000%2C%0A++++++++%22kills%22%3A+6%0A++++%7D%2C%0A++++%22player2%22%3A+%7B%0A++++++++%22money%22%3A+3000%2C%0A++++++++%22kills%22%3A+12%0A++++%7D%2C%0A++++%22player3%22%3A+%7B%0A++++++++%22money%22%3A+2000%2C%0A++++++++%22kills%22%3A+2%0A++++%7D%0A%7D'
   22     1        ASSIGN                                                   !1, 'money'
   23     2        ASSIGN                                                   !2, 'desc'
   24     3        INIT_FCALL                                               'json_decode'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 <true>
          6        DO_ICALL                                         $7      
          7        ASSIGN                                                   !3, $7
   27     8        INIT_FCALL                                               'usort'
          9        SEND_REF                                                 !3
         10        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FiZc0p%3A27%240'
         11        BIND_LEXICAL                                             ~9, !2
         12        SEND_VAL                                                 ~9
         13        DO_ICALL                                                 
   30    14        INIT_FCALL                                               'var_dump'
         15        SEND_VAR                                                 !3
         16        DO_ICALL                                                 
         17      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FiZc0p%3A27%240:
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
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iZc0p
function name:  {closure}
number of ops:  18
compiled vars:  !0 = $playerA, !1 = $playerB, !2 = $order
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
          3        FETCH_DIM_R                                      ~3      !0, 'money'
          4        FETCH_DIM_R                                      ~4      !1, 'money'
          5        IS_SMALLER                                               ~4, ~3
          6      > JMPZ                                                     ~5, ->9
          7    >   QM_ASSIGN                                        ~6      -1
          8      > JMP                                                      ->10
          9    >   QM_ASSIGN                                        ~6      1
         10    >   FETCH_DIM_R                                      ~7      <array>, !2
         11        MUL                                              ~8      ~6, ~7
         12        COALESCE                                         ~9      ~8
         13        QM_ASSIGN                                        ~9      -1
         14        VERIFY_RETURN_TYPE                                       ~9
         15      > RETURN                                                   ~9
         16*       VERIFY_RETURN_TYPE                                       
         17*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FiZc0p%3A27%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.92 ms | 1405 KiB | 19 Q