array_key_exists($key, $array) vs !empty($array[$key])

前端 未结 4 1462
清酒与你
清酒与你 2021-01-01 18:09

I\'ve seen a lot of people do the former, is there any performance benefit doing one vs the other? Or is it just an eye candy? I personally use the latter every time as it i

4条回答
  •  囚心锁ツ
    2021-01-01 18:45

    $array = array(
        'foo' => null
    );
    
    echo (int)!empty($array['foo']); // 0
    echo (int)array_key_exists('foo', $array); // 1
    

提交回复
热议问题