Joseph Witchard
08-01-2008, 11:07 PM
Can you declare PHP variables and then store them in an array? I'm trying to create a script that echos random HTML code every time the page loads, but I wanted to check this before I started. My code will show you what I'm hoping to achieve:
<?php
$var1 = include("file1.html");
$var2 = include("file2.html");
$var3 = include("file3.html");
$var4 = include("file4.html");
$array = array($var1, $var2, $var3, $var4);)
// somewhere in the HTML part of the page
echo $array[rand(0, 3)];
?>
<?php
$var1 = include("file1.html");
$var2 = include("file2.html");
$var3 = include("file3.html");
$var4 = include("file4.html");
$array = array($var1, $var2, $var3, $var4);)
// somewhere in the HTML part of the page
echo $array[rand(0, 3)];
?>