3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = array( array('id' => 1, 'name' => 'John Snow', 'score' => 80), array('id' => 2, 'name' => 'John Fire', 'score' => 50), array('id' => 3, 'name' => 'John Water', 'score' => 79), array('id' => 4, 'name' => 'John Leaf', 'score' => 80), ); function cmp($a, $b) { if ($a['score'] == $b['score']) { return 0; } return ($a['score'] > $b['score']) ? -1 : 1; } uasort($data, 'cmp'); $rank = 1; $prev = false; foreach ($data as $i=>$d) { if (!$prev) { $data[$i]['rank'] = $rank; $prev = $d['score']; continue; } elseif ($prev != $d['score']) { $rank++; } $data[$i]['score'] = $rank; $prev = $d['score']; } print_r($data);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 29
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 29
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 19
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 23
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 23
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/ufRvS
function name:  (null)
number of ops:  34
compiled vars:  !0 = $data, !1 = $rank, !2 = $prev, !3 = $d, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   16     1        INIT_FCALL                                               'uasort'
          2        SEND_REF                                                 !0
          3        SEND_VAL                                                 'cmp'
          4        DO_ICALL                                                 
   18     5        ASSIGN                                                   !1, 1
   19     6        ASSIGN                                                   !2, <false>
   20     7      > FE_RESET_R                                       $9      !0, ->29
          8    > > FE_FETCH_R                                       ~10     $9, !3, ->29
          9    >   ASSIGN                                                   !4, ~10
   21    10        BOOL_NOT                                         ~12     !2
         11      > JMPZ                                                     ~12, ->19
   22    12    >   FETCH_DIM_W                                      $13     !0, !4
         13        ASSIGN_DIM                                               $13, 'rank'
         14        OP_DATA                                                  !1
   23    15        FETCH_DIM_R                                      ~15     !3, 'score'
         16        ASSIGN                                                   !2, ~15
   24    17      > JMP                                                      ->8
         18*       JMP                                                      ->23
   26    19    >   FETCH_DIM_R                                      ~17     !3, 'score'
         20        IS_NOT_EQUAL                                             !2, ~17
         21      > JMPZ                                                     ~18, ->23
   27    22    >   PRE_INC                                                  !1
   29    23    >   FETCH_DIM_W                                      $20     !0, !4
         24        ASSIGN_DIM                                               $20, 'score'
         25        OP_DATA                                                  !1
   30    26        FETCH_DIM_R                                      ~22     !3, 'score'
         27        ASSIGN                                                   !2, ~22
   20    28      > JMP                                                      ->8
         29    >   FE_FREE                                                  $9
   33    30        INIT_FCALL                                               'print_r'
         31        SEND_VAR                                                 !0
         32        DO_ICALL                                                 
         33      > RETURN                                                   1

Function cmp:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ufRvS
function name:  cmp
number of ops:  16
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   10     2        FETCH_DIM_R                                      ~2      !0, 'score'
          3        FETCH_DIM_R                                      ~3      !1, 'score'
          4        IS_EQUAL                                                 ~2, ~3
          5      > JMPZ                                                     ~4, ->7
   11     6    > > RETURN                                                   0
   13     7    >   FETCH_DIM_R                                      ~5      !0, 'score'
          8        FETCH_DIM_R                                      ~6      !1, 'score'
          9        IS_SMALLER                                               ~6, ~5
         10      > JMPZ                                                     ~7, ->13
         11    >   QM_ASSIGN                                        ~8      -1
         12      > JMP                                                      ->14
         13    >   QM_ASSIGN                                        ~8      1
         14    > > RETURN                                                   ~8
   14    15*     > RETURN                                                   null

End of function cmp

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.21 ms | 1400 KiB | 17 Q