Page 1 of 2

Random Echo??????

Posted: Sat Mar 20, 2004 8:45 pm
by davy2001
please will someone please tell me how to make a php do a random echo

i tried this, i know its wrong because i have tested it:

Code: Select all

<?php
echo "message1" | "message2" | "message3" | "etc";
?>
Please help

Posted: Sat Mar 20, 2004 8:50 pm
by d3ad1ysp0rk
psuedo code:

- populate array of things to echo
- pick random number from 0-length of array
- echo array[$randnum]

Posted: Sat Mar 20, 2004 8:51 pm
by davy2001
huh?
i dont quite understand what you mean because im a bit of a newbie

Posted: Sat Mar 20, 2004 8:54 pm
by Illusionist
1) create an array of things you want to say.
2) pick a random number between 0 and the length of the array
3) echo it out like: echo $array_name[$random_number];

Posted: Sat Mar 20, 2004 8:55 pm
by davy2001
whats the script for it?

i only know the basic php

i havnt done anything like this b4

Posted: Sat Mar 20, 2004 8:57 pm
by Illusionist
well, try something first. Do some research on arrays and random numbers. Put somethign together you think will work. Test it. If it breaks, come back and post specific questions!!

Posted: Sat Mar 20, 2004 8:57 pm
by d3ad1ysp0rk
We're not gonna write it for you.

http://php.net/ has the full list of functions.
you need one to make a random number
and one to get the size of the array

Posted: Sat Mar 20, 2004 8:58 pm
by davy2001
ok ok, calm down!!!

MAN, people get so worked up on forums when other people ask for help!

GOD!!!

Posted: Sat Mar 20, 2004 8:59 pm
by Illusionist
LiLpunkSkateR wrote:We're not gonna write it for you.
took the words right outta my mouth! Only i didn't want to say that because many people think its rude and that i'm being rude by telling them i wont write their script for them!!

Posted: Sat Mar 20, 2004 8:59 pm
by Illusionist
davy2001 wrote:ok ok, calm down!!!

MAN, people get so worked up on forums when other people ask for help!

GOD!!!
LOL, see what i mean!!! :lol: :roll:

Posted: Sat Mar 20, 2004 8:59 pm
by d3ad1ysp0rk
umm.. actually.. we get annoyed when people want us to write their code.

if you have a problem, we'll help you with it, but if you're not willing to do some work, then why should we be?

Posted: Sat Mar 20, 2004 9:00 pm
by davy2001
cant anyone read, i said i have already triedwhat i thought would work (read my first post)

Posted: Sat Mar 20, 2004 9:01 pm
by Illusionist
If you want to learn the language then you have to try things first. If you just want everyone else to do the work for you, then give up programming/scripting w/e. Just throw your computer away and hide under your bed! hehe

Posted: Sat Mar 20, 2004 9:01 pm
by Illusionist
davy2001 wrote:cant anyone read, i said i have already triedwhat i thought would work (read my first post)
And we both gave you suggestions of what to do. Did you try any of that??

Didn't think so!

Posted: Sat Mar 20, 2004 9:02 pm
by d3ad1ysp0rk
Davy, have you visited php.net?

and what tutorial(s) did you use to start learning?