Javascript / jQuery / PHP Help.

Status
Not open for further replies.

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Hello,

I've given the title what it is because I don't know what language to do what I want, but I guessed it would be used with one of the ones in the title.

Is there anyway I can get the browser to display a random string from an array everytime the page is refreshed
so I could have:

$a[] = "My name is Josh";
$a[] = "My age is 17";
$a[] = "I live in England";

When the browser is first loaded for instance "My age is 17" would appear in a div or a span & then when the browser is refreshed maybe "My name is Josh" would appear in the div / span.

Any help would be appreciated, thanks!
 

Kryptos

prjRev.com
Jul 21, 2010
2,205
1,252
What you should do goes as follow..

var num = produce random number

array[] = string
array[] = string2
array[] = string 3

output array[num]
 

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Can't seem to get this to work. Dwight's code seems to give out: "Parse error: syntax error, unexpected ']' in C:\xampp\htdocs\poop.php on line 46" and when using Kryptos' using JavaScript nothing appears.
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,639
2,397
PHP:
<?php
$array = array( "My name is Josh", "I am 17", "I live in England" );
echo $array[mt_rand(0, count($array))];
?>

or something. i unno, it's 3am, im very tired and not done any php in about 2 or 3 weeks
 

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Hmmm, yours seems to get to display two then when it tries to display the third ("I live in England") it gives: Notice: Undefined offset: 3 in C:\xampp\htdocs\poop.php on line 44
 
Status
Not open for further replies.

Users who are viewing this thread

Top