Hi i am trying to work out a Random Include script so if i use the script it will populate a div / section of my site from a list of files I have defined, any ideas ? switch statement trickery?
<?php $files = array("file1.php","file2.php","file3.php"); $selected_file = $files[rand(0,count($files)-1)]; include($selected_file); ?>
Or you can use array_rand function : array_rand ($file_array, $numberofitemstoget) <?php $input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank"); $rand_keys = array_rand($input, 2); echo $input[$rand_keys[0]] . "\n"; echo $input[$rand_keys[1]] . "\n"; ?> Code (markup):