1
Hello, I have a number of phrases, and I need that every time the user sent a certain form, appeared one of these phrases, using a random function, but I do not even know how to start, I have no code so far.
1
Hello, I have a number of phrases, and I need that every time the user sent a certain form, appeared one of these phrases, using a random function, but I do not even know how to start, I have no code so far.
5
From what you specified in your question I can give you an idea of how to do this simply, use an array to store your sentences and have the function array_rand() resume an Indice random that will be the chosen phrase.
$frases = array('frase 1','frase 2','frase 3','frase 4');
echo $frases[array_rand($frases)];
See working on Ideone
4
Try this way
$array = array(
'Frase 1',
'Frase 2',
'Frase 3'
);
$aleatorio = rand(0, count($array) -1);
echo $array[$aleatorio];
It worked right, thank you!
Browser other questions tagged php random
You are not signed in. Login or sign up in order to post.
Those phrases are where?
– rray
And will appear where?
– Caio Felipe Pereira
@rray they will be written in advance, if applicable, they will receive the value of a variable
– Jorge Felix
@Caiofelipepereira will appear as soon as the user logs into their account.
– Jorge Felix
Are in a? file in the bank? is one per user?
– rray
@rray they do not yet have a specific location, where it would be easier to use them?
– Jorge Felix
Will they appear when the user sends the form (on the login screen, I presume), or on the next screen after logging in? I can see that your question is very comprehensive, right?!
– Caio Felipe Pereira