Skip to content

Instantly share code, notes, and snippets.

@jeffreyroberts
Last active December 22, 2015 03:09
Show Gist options
  • Select an option

  • Save jeffreyroberts/6408684 to your computer and use it in GitHub Desktop.

Select an option

Save jeffreyroberts/6408684 to your computer and use it in GitHub Desktop.
PHP - load random queue from file with lines terminated by \n
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;
}
@jeffreyroberts

Copy link
Copy Markdown
Author

This function was not designed for performance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment