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 uasort($dataset, fn (array $playerA, array $playerB): int => ($playerA['money'] > $playerB['money'] ? -1 : 1) * ['desc' => 1, 'asc' => -1][$order] ?? -1); // Print results var_dump($dataset); $i = 1; foreach($dataset as $player => $data) { echo "#$i: $player (\${$data['money']})" . PHP_EOL; $i ++; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 33
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 33
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/csjEl
function name:  (null)
number of ops:  35
compiled vars:  !0 = $json, !1 = $sortBy, !2 = $order, !3 = $dataset, !4 = $i, !5 = $data, !6 = $player
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                                         $10     
          7        ASSIGN                                                   !3, $10
   27     8        INIT_FCALL                                               'uasort'
          9        SEND_REF                                                 !3
         10        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FcsjEl%3A27%240'
         11        BIND_LEXICAL                                             ~12, !2
         12        SEND_VAL                                                 ~12
         13        DO_ICALL                                                 
   30    14        INIT_FCALL                                               'var_dump'
         15        SEND_VAR                                                 !3
         16        DO_ICALL                                                 
   32    17        ASSIGN                                                   !4, 1
   33    18      > FE_RESET_R                                       $16     !3, ->33
         19    > > FE_FETCH_R                                       ~17     $16, !5, ->33
         20    >   ASSIGN                                                   !6, ~17
   35    21        ROPE_INIT                                     7  ~21     '%23'
         22        ROPE_ADD                                      1  ~21     ~21, !4
         23        ROPE_ADD                                      2  ~21     ~21, '%3A+'
         24        ROPE_ADD                                      3  ~21     ~21, !6
         25        ROPE_ADD                                      4  ~21     ~21, '+%28%24'
         26        FETCH_DIM_R                                      ~19     !5, 'money'
         27        ROPE_ADD                                      5  ~21     ~21, ~19
         28        ROPE_END                                      6  ~20     ~21, '%29'
         29        CONCAT                                           ~25     ~20, '%0A'
         30        ECHO                                                     ~25
   36    31        PRE_INC                                                  !4
   33    32      > JMP                                                      ->19
         33    >   FE_FREE                                                  $16
   37    34      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FcsjEl%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/csjEl
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%2FcsjEl%3A27%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.98 ms | 1405 KiB | 19 Q