Php random order for imported .php pages [solved]

Viewed 68

Version with 1 result

<?php
srand();
$files = array("folder/content1.php", "folder/content2.php", "folder/content3.php", "folder/content4.php", "folder/content5.php", "folder/content6.php");
$rand = array_rand($files);
include ($files[$rand]);
?>

Version with 5 results (provided by Code Spirit)

<?php
$files = array("folder/content1.php", "folder/content2.php", "folder/content3.php", "folder/content4.php", "folder/content5.php", "folder/content6.php");
foreach (array_rand($files, 5) as $file) {
  include($files[$file]);
}

?>
1 Answers

You need a loop.

foreach (array_rand($files, 3) as $file) {
  include($files[$file]);
}
Related