3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $arr = array( array("url" => "http://google.com", "priority" => 2), 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[$nbOfElement];
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
Notice: Undefined offset: 10 in /in/MkjPr on line 31
Output for hhvm-3.12.0
Notice: Undefined index: 10 in /in/MkjPr on line 31
Output for hhvm-3.10.0

Process exited with code 153.
Output for 4.3.0 - 5.2.17
Notice: Undefined offset: 10 in /in/MkjPr on line 31