Jump to content

Random Script


mcmuney

Recommended Posts

I am so confused with your question, but maybe this will help

 

 

<?php
$arr1 = array('Audi','Ford','Honda','Toyota');
$arr2 = array('Audi','Ford','Honda','Toyota');
$arr3 = array('Audi','Ford','Honda','Toyota');
$arr4 = array('Audi','Ford','Honda','Toyota');
shuffle($arr1);
shuffle($arr2);
shuffle($arr3);
shuffle($arr4);
//Take one random line from below
define('DEFAULT_TERM', $arr1);
define('DEFAULT_TERM', $arr2);
define('DEFAULT_TERM', $arr3);
define('DEFAULT_TERM', $arr4);
?>

Link to comment
https://forums.phpfreaks.com/topic/91361-random-script/#findComment-468161
Share on other sites

Looking for a simple random script, something like the one below where the script will take only one line:

 

//Take one random line from below
define('DEFAULT_TERM', 'Audi');
define('DEFAULT_TERM', 'Ford');
define('DEFAULT_TERM', 'Honda');
define('DEFAULT_TERM', 'Toyota');

 

I was confuse about the question. If you want to use or make it random simply use MT_RAND() or RAND function (using dtabase).

Link to comment
https://forums.phpfreaks.com/topic/91361-random-script/#findComment-468191
Share on other sites

<?php
session_start();
echo count($_SESSION['randomNums']) . "<br>";
print_r($_SESSION['randomNums']);
function randomNoRepeat(){
$max= 6;
$num = Rand (1,$max);
if(isset($_SESSION['randomNums']) && in_array($num,$_SESSION['randomNums'])){
	if (count($_SESSION['randomNums']) == 6){
		switch ($num)
		{
		case 1:
		echo "Time is money";
		break;
		case 2:
		echo "An apple a day keeps the doctor away";
		break;
		case 3:
		echo "Elmo loves dorthy";
		break;
		case 4:
		echo "Off to see the wizard";
		break;
		case 5:
		echo "Tomorrow is another day";
		break;
		case 6:
		echo "PHP is cool!";
		}
		unset($_SESSION['randomNums']);
	}else{
		randomNoRepeat();
	}
}else{
	switch ($num)
	{
	case 1:
	echo "Time is money";
	$_SESSION[randomNums][] = $num;
	break;
	case 2:
	echo "An apple a day keeps the doctor away";
	$_SESSION[randomNums][] = $num;
	break;
	case 3:
	echo "Elmo loves dorthy";
	$_SESSION[randomNums][] = $num;
	break;
	case 4:
	echo "Off to see the wizard";
	$_SESSION[randomNums][] = $num;
	break;
	case 5:
	echo "Tomorrow is another day";
	$_SESSION[randomNums][] = $num;
	break;
	case 6:
	echo "PHP is cool!";
	$_SESSION[randomNums][] = $num;
	}
}
}
randomNoRepeat();
?>

Link to comment
https://forums.phpfreaks.com/topic/91361-random-script/#findComment-468209
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.