3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(E_ALL | E_STRICT); ini_set('display_errors', 1); // your original input $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 = 17, Position 2 = 31
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 31
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/Hgj5P
function name:  (null)
number of ops:  36
compiled vars:  !0 = $original, !1 = $rankings, !2 = $return, !3 = $value, !4 = $rankedValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 32767
          2        DO_ICALL                                                 
    3     3        INIT_FCALL                                               'ini_set'
          4        SEND_VAL                                                 'display_errors'
          5        SEND_VAL                                                 1
          6        DO_ICALL                                                 
    6     7        ASSIGN                                                   !0, <array>
    9     8        INIT_FCALL                                               'array_unique'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $8      
         11        ASSIGN                                                   !1, $8
   12    12        INIT_FCALL                                               'rsort'
         13        SEND_REF                                                 !1
         14        DO_ICALL                                                 
   15    15        ASSIGN                                                   !2, <array>
   16    16      > FE_RESET_R                                       $12     !0, ->31
         17    > > FE_FETCH_R                                               $12, !3, ->31
   18    18    >   ASSIGN                                                   !4, <array>
   19    19        ASSIGN_DIM                                               !4, 'value'
         20        OP_DATA                                                  !3
   20    21        INIT_FCALL                                               'array_search'
         22        SEND_VAR                                                 !3
         23        SEND_VAR                                                 !1
         24        DO_ICALL                                         $16     
         25        ADD                                              ~17     $16, 1
         26        ASSIGN_DIM                                               !4, 'rank'
         27        OP_DATA                                                  ~17
   21    28        ASSIGN_DIM                                               !2
         29        OP_DATA                                                  !4
   16    30      > JMP                                                      ->17
         31    >   FE_FREE                                                  $12
   24    32        INIT_FCALL                                               'var_dump'
         33        SEND_VAR                                                 !2
         34        DO_ICALL                                                 
         35      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.1 ms | 1401 KiB | 25 Q