Random Echo??????

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

davy2001
Forum Commoner
Posts: 37
Joined: Tue Feb 24, 2004 5:59 pm

Random Echo??????

Post 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
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

psuedo code:

- populate array of things to echo
- pick random number from 0-length of array
- echo array[$randnum]
davy2001
Forum Commoner
Posts: 37
Joined: Tue Feb 24, 2004 5:59 pm

Post by davy2001 »

huh?
i dont quite understand what you mean because im a bit of a newbie
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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];
davy2001
Forum Commoner
Posts: 37
Joined: Tue Feb 24, 2004 5:59 pm

Post by davy2001 »

whats the script for it?

i only know the basic php

i havnt done anything like this b4
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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!!
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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
davy2001
Forum Commoner
Posts: 37
Joined: Tue Feb 24, 2004 5:59 pm

Post by davy2001 »

ok ok, calm down!!!

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

GOD!!!
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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!!
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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:
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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?
davy2001
Forum Commoner
Posts: 37
Joined: Tue Feb 24, 2004 5:59 pm

Post by davy2001 »

cant anyone read, i said i have already triedwhat i thought would work (read my first post)
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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!
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Davy, have you visited php.net?

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