I have about 300 lines of text that need to be echoed randomly.
Here's my current code:
<?php
$lines = array(
'Line 1',
'Line 2',
'Line 3'
);
$powered = echo $lines[rand(0, count($lines)-1)];
echo $powered;
?>
I know that the issue is probably with line 9 because I'm not sure how to assign the echoing to a variable. I need to be able to include this file in several others and echo $powered
to get a random line.
Any help would be really appreciated.
$lines = array("one", "two", "three","four");
for($i =0; i < count($lines)-1;i++){
$line = $lines[rand(0, count($lines)-1)];
$lines = array_diff($lines, array($line));//Use this to remove the index of array
}
i wrote this in the stack overflow chat so there might be a problem or two. though, all looks well to me.
Was this what you were looking for?