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), ); $score = array(); foreach ($data as $idx => $dataInd) { $score[$dataInd['score']] = $dataInd['score']; } rsort($score); foreach ($data as $idx => $dataInd) { $data[$idx]['rank'] = array_search($dataInd['score'], $score) + 1; } print_r($data);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 10
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 27
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 27
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
Branch analysis from position: 10
filename:       /in/njLI1
function name:  (null)
number of ops:  32
compiled vars:  !0 = $data, !1 = $score, !2 = $dataInd, !3 = $idx
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   10     1        ASSIGN                                                   !1, <array>
   11     2      > FE_RESET_R                                       $6      !0, ->10
          3    > > FE_FETCH_R                                       ~7      $6, !2, ->10
          4    >   ASSIGN                                                   !3, ~7
   12     5        FETCH_DIM_R                                      ~9      !2, 'score'
          6        FETCH_DIM_R                                      ~11     !2, 'score'
          7        ASSIGN_DIM                                               !1, ~9
          8        OP_DATA                                                  ~11
   11     9      > JMP                                                      ->3
         10    >   FE_FREE                                                  $6
   15    11        INIT_FCALL                                               'rsort'
         12        SEND_REF                                                 !1
         13        DO_ICALL                                                 
   17    14      > FE_RESET_R                                       $13     !0, ->27
         15    > > FE_FETCH_R                                       ~14     $13, !2, ->27
         16    >   ASSIGN                                                   !3, ~14
   18    17        INIT_FCALL                                               'array_search'
         18        FETCH_DIM_R                                      ~18     !2, 'score'
         19        SEND_VAL                                                 ~18
         20        SEND_VAR                                                 !1
         21        DO_ICALL                                         $19     
         22        ADD                                              ~20     $19, 1
         23        FETCH_DIM_W                                      $16     !0, !3
         24        ASSIGN_DIM                                               $16, 'rank'
         25        OP_DATA                                                  ~20
   17    26      > JMP                                                      ->15
         27    >   FE_FREE                                                  $13
   21    28        INIT_FCALL                                               'print_r'
         29        SEND_VAR                                                 !0
         30        DO_ICALL                                                 
         31      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.75 ms | 1396 KiB | 19 Q