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']; } } echo '<pre>'; die(print_r($listOfUrl));
Output for 4.3.0 - 7.1.0
<pre>Array ( [0] => http://google.com [1] => http://google.com [2] => http://facebook.com [3] => http://facebook.com [4] => http://youtube.com [5] => http://youtube.com [6] => http://stackoverflow.com [7] => http://kickass.to [8] => http://twitter.com [9] => http://example.com ) 1