mardi 18 août 2015

Struggling getting random string from an array in php

Ok, I've got this array and I want to get a random array from it every time. I have looked up and got an answer, but it shows not what I want on my website.

The array is in this variable called $statusarray and when I print_r this variable, I get this:

Array(
    [0] => aa
    [1] => bb
    [2] => cc
    [3] => dd
    [4] => ee
    [5] => ff
)

I know that you do $randomstatus = array_rand($statusarray, 1); to get one random entry from the array as written on http://ift.tt/187g620. and I print_r or echo it.

However, when I do it, it comes up with a random number from 1-5 and then followed by NULL

What is wrong with my code, or is there another way to do it?

Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire