My config.php contains:
$a1="title";
$b1="text";
$a2="title2";
$b2="text2";
and I have 1.php which includes config.php.
I need to include ($a1 and $b1) or ($a and $b) randomly.
How can I do this? :)
Thank you.
If this data is related, and you need a random set, store it in an array:
$sets = array(
array(
'title' => 'Some title',
'text' => 'Some text here about the title'
),
array(
'title' => 'Some other title',
'text' => 'Some other text here about the title'
)
);
With this array, we have two indexes that we can choose from:
$sets[0]; // Title: Some title, Text: Some text here about the title
$sets[1]; // Title: Some other title, Text: Some other text here about the title
If we want one of those, randomly, we could do the following:
$index = array_rand( $sets, 1 );
This will select either 0, or 1. With more entries in our array, the potential for this number to be larger also increases. We can then use it to grab one of our sets of data:
$dataSet = $sets[ $index ];
And then display the output:
echo $dataSet['title'];
echo $dataSet['text'];
$aand$b. Then pick a random index$iand use it as$a[$i]and$b[$i]