简体   繁体   中英

PHP check any key of array has null value

I have a array like

$question = array(
'description'=>'some description',
'answer_one'=>'some answer',
'answer_two' => NULL)

I need to check any key of this array contains null value in quickest way.

$key = array_search(null, $question);

Try this:

$question = array(
'description'=>'some description',
'answer_one'=>'some answer',
'answer_two' => NULL);

foreach ($question as $key => $value) {
    if ($value == "") {
echo $key . " is empty!";
}

}
if (in_array(NULL, $question)) {

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM