I have a form where user insert their names, once they submit the form, the page should check if the name provided already exists, if so, should return with an error, other wise
Just make use of a multi-level break
statement and come out of the loop.
Something like
if (count($keys)>0)
{
// Add the key to the temp array so its not found again:
$temp[] = $key;
// Do something...
echo '<li>Name already used';
break 3;
}
I got it from your comments that you have the following:
$_POST["user-submitted-name"]; // name from the form
$names = get_meta_values('user_submit_name'); // array with names not allowed
Then it looks like the easy way:
if (in_array($_POST["user-submitted-name"], $names)) {
// posting not allowed
echo '<li>Name already used';
} else {
// posting is allowed
// save posting here...
// and then go to success page:
header("Location: success.html"); // redirect
exit(); // and stop here
}