$array=array(); $count=0; if (preg_match("/mp3$/", "$file")){ $array[$count] = "http://localhost/?dir=$dir&play=$pathfromroot"; $count=$count+1; } } $rand_keys = array_rand($array, 1); $page = $array[$rand_keys]; echo ""; $array[0] will return the first value, 1-x will be empty.. Any idea on why the Array is failing to be populated?