Check if value isset and null

前端 未结 8 473
迷失自我
迷失自我 2020-11-30 01:26

I need to check if value is defined as anything, including null. isset treats null values as undefined and returns false. Take the following as an

8条回答
  •  野性不改
    2020-11-30 02:13

    IIRC, you can use get_defined_vars() for this:

    $foo = NULL;
    $vars = get_defined_vars();
    if (array_key_exists('bar', $vars)) {}; // Should evaluate to FALSE
    if (array_key_exists('foo', $vars)) {}; // Should evaluate to TRUE
    

提交回复
热议问题