Accessing arrays whitout quoting the key

前端 未结 3 1351
余生分开走
余生分开走 2020-12-04 02:43

I can access an array value either with $array[key] or $array[\'key\']

Is there a reason to avoid using one over the other?

3条回答
  •  星月不相逢
    2020-12-04 03:28

    $array[key] is not correct usage. In this case 'key' will be treated as a constant (i.e., via define()) instead of a string. In the case where there is no constant named key, PHP will assume you mean 'key' and "fix" it for you and throw a warning.

提交回复
热议问题