How can i pull random name from the Array?
...
$all = "$a1$b1$c1$d1$e1";
$all = print_r(explode("<br>",$all));
echo $all;
----
Array ( [0] => lizzy [1] => rony [2] => )
I need random text to appear in echo
How can i pull random name from the Array?
...
$all = "$a1$b1$c1$d1$e1";
$all = print_r(explode("<br>",$all));
echo $all;
----
Array ( [0] => lizzy [1] => rony [2] => )
I need random text to appear in echo
echo $input[array_rand($all)];
This gets a random index in the array and then echos the value.
Get random characters:
rand_chars("ABCEDFG", 10); // Output: GABGFFGCDA
Get random number:
echo rand(1, 10000); // Output: 5482
If you want to have a random string based on given input:
$chars = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
$clen = strlen( $chars )-1;
$id = '';
$length = 10;
for ($i = 0; $i < $length; $i++)
{
$id .= $chars[mt_rand(0,$clen)];
}
echo ($id); // Output: Gzt6syUS8M
Documentation: http://php.net/manual/en/function.rand.php
` tags? Why are you assigning the result of a call to `print_r` and then echo-ing it? This looks like the code you end up with after trying lots of things and not removing them when they don't work. – iainn Mar 19 '18 at 16:07