I have an variable called $vars which contains an array that is submitted with form:
Array
(
[name] => Sample Name
[email] => [email protected]
[job_role] =>
[telephone_number] => telephone number
[comment] => comment
)
How can I check if job_role index is containing a value?
I tried:
if (in_array('', $vars)){
echo "Job role can't be empty";
} else {
echo "Job role submitted";
}
But this works on the whole array and not only the job_role index.
Also, I tried:
if (isset($vars['job_role'])){
echo "match found";
} else {
echo "nothing there";
}
But it was returning "match found" even when I didn't submit anything...
Why is isset() always returning true?
isset()checks if the value defined (is set), not it is empty. In your code$vars['job_role']is probably an empty string, so, it's defined, but it's empty.