I am trying to re-create an array by choosing random elements of an existing array using array_rand().
However, when using the following code and spitting out the array, I am getting an undefined index error in reference to it.
The array is $city_users_trimmed
.
PHP code:
$rand = array_rand($city_users_trimmed, 1);
$data = array($city_users_trimmed[$rand[0]]);
I know that $city_users_trimmed has at least 1 element in it, so there is no reason I see why this wouldn't be working.
I tested it by running:
$data = array($city_users_trimmed[0]);
which works, so there is at least one element in the $city_users_trimmed array. Is there anything you see that is causing this issue? Thank you.