I have an array that's accessed via $request (this is not the same as $_REQUEST). The array print_r's out as
Array
(
[num_days] => 30
[customer_id] => 5
)
The num_days key may or may not exist (it can be any number of things.) I need to test to see if the key exists. I've tried this:
if(array_key_exists($request['num_days'], $request)) {
echo "num_days exists";
}
else {
echo "num_days doesn't exist";
}
This always hits the else. Am I doing this wrong? Is num_days not considered a key? If not, how can I test for the existence of that element (NOT the value of it, but whether it exists at all)?
array_key_exists('num_days', $request)isset()andarray_key_exists()are not totally the same. If the value was set, but wasNULL, thenisset()would returnfalse, butarray_key_exists()would returntrue.