Newbie here attempting to make a simple function, I think I'm close to a solution, but I'm stuck currently with an illegal offset type.
The function will, based on the number of keys, select one of the keys randomly and then propagate my echo statement so that the desired data will then propagate the function echo statements. i.e. if key '3' is selected, the Username, first name, and last name will be populated with the data associated with the third key '[3]' of the array '$aaUser'.
I have tried searching stack overflow, php.net and googled to try to find a solution to attempt to resolve this function but as yet I have not found an answer which I can understand at this time.
my example array:
$aaUser = [ //Make multidimensional
// 0 => nameUser
// 1 => namefirst
// 2 => namelast
0 => ["monkeework", "my", "name"],
1 => ["mentor", "Portia", "Plante"],
2 => ["teacher", "Bill", "Newman"],
3 => ["friend", "Sage", "Gerky"],
4 => [ "pet", "pedro", "" //last postion left empty - if empty we skip]
];
my function:
function getRandomUser($arr){
$myKey = array_rand($arr);
$myValue = $arr[$myKey];
echo 'Username: ' . $arr[$myValue][0] . '<br />';
echo 'Name: ' . $arr[$myValue][1] . ' ' . $arr[$myValue][2] . '<br /><br />';
How I call the function:
getRandomUser($aaUser);//select array, get array data back as echo statements