开发者

Using arrays without putting the key in quotes?

It used to be that if you did this:

$foo[bar] = true;

instead of:

$foo['bar'] = true;

you would get a 'Notice' error. However now with PHP 5, I no longer seem开发者_如何学JAVA to get this error? Has this been changed?


Probably error reporting is turned off.

Try at top of the code:

ini_set("display_errors", true);
error_reporting(E_ALL);


They still trigger that notice, so you must have disabled notices from being displayed on screen.


In fact, this question has nothing to do with arrays. It's string bar you're typing against rules, as strings should be always quoted in PHP.

While array keys has nothing to do with quotes. In PHP you can use almost every language construct that returns scalar value to be used as a key. Only square brackets belongs to array syntax. Everything between them is just going to be regular PHP expression with it's usual rules.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜