Last active
December 22, 2015 03:09
-
-
Save jeffreyroberts/6408684 to your computer and use it in GitHub Desktop.
PHP - load random queue from file with lines terminated by \n
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function load_queues($path) { | |
$queuesTemp = array(); | |
$contents = file_get_contents($path); | |
$contents = explode("\n", $contents); | |
foreach($contents as $content) | |
{ | |
if(!in_array(trim($content), $queuesTemp)) { | |
$queuesTemp[] = trim($content); | |
} | |
} | |
$removeat = array(); | |
$queues = array(); | |
foreach($queuesTemp as $queue) { | |
$b = rand(0, count($queuesTemp) - 1); | |
while(in_array($b, $removeat)) { | |
$b = rand(0, count($queuesTemp) - 1); | |
} | |
$queues[$b] = $queue; | |
$removeat[] = $b; | |
} | |
return $queues; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This function was not designed for performance