3v4l.org

run code in 300+ PHP versions simultaneously
<?php $original = array(12, 17, 5, 27, 5); // strip duplicates as they are ranked equally $rankings = array_unique($original); // apply some sorting so that the ranks are now given by the keys. rsort($rankings); // now just use the origincal array and lookup the rankings for each value $return = array(); foreach($original as $value) { $rankedValue = array(); $rankedValue['value'] = $value; $rankedValue['rank'] = array_search($value, $rankings) + 1; $return[] = $rankedValue; } var_dump($return);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 24
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 24
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/MEq5d
function name:  (null)
number of ops:  29
compiled vars:  !0 = $original, !1 = $rankings, !2 = $return, !3 = $value, !4 = $rankedValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    5     1        INIT_FCALL                                               'array_unique'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $6      
          4        ASSIGN                                                   !1, $6
    8     5        INIT_FCALL                                               'rsort'
          6        SEND_REF                                                 !1
          7        DO_ICALL                                                 
   11     8        ASSIGN                                                   !2, <array>
   12     9      > FE_RESET_R                                       $10     !0, ->24
         10    > > FE_FETCH_R                                               $10, !3, ->24
   14    11    >   ASSIGN                                                   !4, <array>
   15    12        ASSIGN_DIM                                               !4, 'value'
         13        OP_DATA                                                  !3
   16    14        INIT_FCALL                                               'array_search'
         15        SEND_VAR                                                 !3
         16        SEND_VAR                                                 !1
         17        DO_ICALL                                         $14     
         18        ADD                                              ~15     $14, 1
         19        ASSIGN_DIM                                               !4, 'rank'
         20        OP_DATA                                                  ~15
   17    21        ASSIGN_DIM                                               !2
         22        OP_DATA                                                  !4
   12    23      > JMP                                                      ->10
         24    >   FE_FREE                                                  $10
   20    25        INIT_FCALL                                               'var_dump'
         26        SEND_VAR                                                 !2
         27        DO_ICALL                                                 
         28      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.89 ms | 1396 KiB | 21 Q