You are searching the wrong array to start with and echoing the wrong array too.
$users_emails = array('Spence', 'Matt', 'Marc', 'Adam', 'Paul');
$current = 'Spence';
$ordinal = (array_search($current,$users_emails)+1);
$next = $users_emails[$ordinal];
echo $next;
See my code, I search for Spence in the array with names and it returns a key number.
This key number should echo in user emails not keys.
https://3v4l.org/0gJ1m
If you need it to work with associative arrays you need to do like this:
$users_emails = array('a' => 'Spence', 'b' => 'Matt', 'c' => 'Marc', 'd' => 'Adam', 'e' => 'Paul');
$keys = array_values(array_keys($users_emails));
$current = 'Matt';
$next = ""; // set to not get notice if end of array
$ordinal = array_search($current,$users_emails);
$nextkey = (array_search($ordinal, $keys)+1);
If(!isset($keys[$nextkey])){
// what to do if your at the end of array
// $nextkey = 0;
// Echo "message";
// Or whatever you want
}else{
$next = $users_emails[$keys[$nextkey]];
}
echo $next;
I use array_values on the keys to get a indexed array that accepts +1
to find the next key in the array.
https://3v4l.org/iVO6U