samedi 1 juillet 2017

Need a code to choose randomly between options

I have a code to choose 4 options from a group and put it in a string but I have a little problem there.
these are my default data :

$PID[1] = "PID1";
$CID[1] = "CID1";
$PID[2] = "PID2";
$CID[2] = "CID2";
$PID[3] = "PID3";
$CID[3] = "CID3";
$PID[4] = "PID4";
$CID[4] = "CID4";

I create a file with name Loops.php and put these code in it :

$Also = "1";
while (isset($PID[$Also])) {
echo '"'.$CID[$Also]."/".$PID[$Also].".php".'"';
$Also++;
if (isset($PID[$Also])) {
    echo ", ";   
}
}

and then I used this code in my main page :

$input = array(include 'Loops.php');
$rand_keys = array_rand($input, 4);
$A = $input[$rand_keys[0]];
$B = $input[$rand_keys[1]];
$C = $input[$rand_keys[2]];
$D = $input[$rand_keys[3]];

but when I echo any of final strings it does not work.
I will be appreciated if anyone could help me with that.




Aucun commentaire:

Enregistrer un commentaire