My code is
$arr = array(
"key" => array(
"id"
)
);
I have done speed test -> 10k times repeating this both statements with average times both 0.000002. Both does not generate a warning if the variable does not exist.
I am asking, is there any difference?
Which should I better use in my scripts?
the different is that with the empty
function you explicit check if the key your are trying to access in this array exists and prevent a error message if you are trying to access a array key that not exists.
the @
before the array access just says to hide all errors that are generated by this line. so ether the key is present in your array you just say "how cares if there is any error - hide it" the proper way is to use the empty
or isset
function to check first if the array key exists or not.
never hide errors, prevent them with the correct way to access arrays.