3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array( array("url" => "http://google.com", "priority" => 3), array("url" => "http://facebook.com", "priority" => 2), array("url" => "http://youtube.com", "priority" => 2), array("url" => "http://stackoverflow.com", "priority" => 1), array("url" => "http://kickass.to", "priority" => 1), array("url" => "http://twitter.com", "priority" => 1), array("url" => "http://example.com", "priority" => 1), ); // Recreate another array where we have multiple occurence of the same value (nb_of_occurence = priority) $listOfUrl = array(); foreach ($arr as $url) { $nbOfOccurence = $url['priority']; for($i = 0 ; $i < $nbOfOccurence ; $i++) { $listOfUrl[] = $url['url']; } } // Count the number of elements in this new array $nbOfElement = count($listOfUrl); // Generate a random index between 0 and (number of element - 1) $randomIndex = rand(0,($nbOfElement - 1)); // Retrive the random value $randomURL = $listOfUrl[$randomIndex]; echo $randomURL;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 15
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 8
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 8
Branch analysis from position: 14
Branch analysis from position: 8
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/81vRh
function name:  (null)
number of ops:  28
compiled vars:  !0 = $arr, !1 = $listOfUrl, !2 = $url, !3 = $nbOfOccurence, !4 = $i, !5 = $nbOfElement, !6 = $randomIndex, !7 = $randomURL
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   14     1        ASSIGN                                                   !1, <array>
   15     2      > FE_RESET_R                                       $10     !0, ->15
          3    > > FE_FETCH_R                                               $10, !2, ->15
   16     4    >   FETCH_DIM_R                                      ~11     !2, 'priority'
          5        ASSIGN                                                   !3, ~11
   18     6        ASSIGN                                                   !4, 0
          7      > JMP                                                      ->12
   19     8    >   FETCH_DIM_R                                      ~15     !2, 'url'
          9        ASSIGN_DIM                                               !1
         10        OP_DATA                                                  ~15
   18    11        PRE_INC                                                  !4
         12    >   IS_SMALLER                                               !4, !3
         13      > JMPNZ                                                    ~17, ->8
   15    14    > > JMP                                                      ->3
         15    >   FE_FREE                                                  $10
   25    16        COUNT                                            ~18     !1
         17        ASSIGN                                                   !5, ~18
   28    18        INIT_FCALL                                               'rand'
         19        SEND_VAL                                                 0
         20        SUB                                              ~20     !5, 1
         21        SEND_VAL                                                 ~20
         22        DO_ICALL                                         $21     
         23        ASSIGN                                                   !6, $21
   31    24        FETCH_DIM_R                                      ~23     !1, !6
         25        ASSIGN                                                   !7, ~23
   33    26        ECHO                                                     !7
         27      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.01 ms | 1388 KiB | 15 Q