php – 关联数组索引命名约定
作者:互联网
在PHP中,关联数组索引需要遵循相同的规则和变量名称(不能以数字开头等).我正在寻找这个问题的工作和哲学答案.
解决方法:
从manual:
A key may be either an integer or a string. If a key is the standard representation of an integer, it will be interpreted as such (i.e. “8” will be interpreted as 8, while “08” will be interpreted as “08”). Floats in key are truncated to integer. The indexed and associative array types are the same type in PHP, which can both contain integer and string indices.
在他们的例子中,使用像$array [“08”]这样的东西是完全可以接受的,并且算作一个字符串,尽管你可以知道,但这是非常不推荐的.始终以逻辑方式命名变量.
标签:php,arrays,naming-conventions,associative 来源: https://codeday.me/bug/20190610/1209982.html