What is the best way to access unknown array elements without generating PHP notice?

前端 未结 2 2020
既然无缘
既然无缘 2020-12-10 21:34

If I have this array,

ini_set(\'display_errors\', true);
error_reporting(E_ALL);

$arr = array(
  \'id\' => 1234,
  \'name\' => \'Jack\',
  \'email\' =         


        
2条回答
  •  醉话见心
    2020-12-10 22:02

    The @ error control operator suppresses any errors generated by an expression, including invalid array keys.

    $name = @$arr['city']['country']['name'];
    

提交回复
热议问题