I have an array that outputs the following:
Array ( [roi_data] => Array (
[0] => Array ( [title] => Test ROI )
[1] => Array ( [title] => Another ROI )
))
I’d like to combine all the keys with title into one array and then echo a random value out of it.
I have tried using array_rand() but I just get the word Array to appear.
You have a multidimensional array. When you call
array_rand, you’re getting back a random element from the first tier of arrays — this element would be an array itself.So, if you wanted a random element from the
roi_datalevel, you’d have to specify that:Documentation
array_rand– http://php.net/manual/en/function.array-rand.php