Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.