Hello,
I have this issue with the following code. I'm trying to generate random words from an array of given words. The problem is that I do not want to limit/force the ammount of words it needs to be able to randomize.
baisically I want to be able to put :
randomtext("word1","word2","word3","word4")
randomtext("word5","word6")
randomtext("word7","word8","word9")
so that the function takes in consiteration the words no matter the ammount 2 or 20 and randomizes the output.
Is there anyway to include all variables from function in the array ?
here is the code :
<?php
$limit=10; // set how many vatriations are wanted
function randomtext($value1,$value2,$value3,$value4) //setting funtion
{
$words = array($value1,$value2,$value3,$value4); //getting words from function
$word = array_rand($words,1); // pick one random word
return $words[$word]; // return picked word
}
if(empty($i)) { //decleare value of $i
$i=1; }
while($i<$limit) // do loop
{
echo randomtext("favorite","best","awsome","excellent").' - '.randomtext("test1","test2","test3","test4").'<br />'; //echo words
$i++; } //inrease value
?>
Thank you