gpt4 book ai didi

php - 关联数组索引命名约定

转载 作者:可可西里 更新时间:2023-10-31 22:06:33 24 4
gpt4 key购买 nike

在 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 - 关联数组索引命名约定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7084777/

24 4 0
文章推荐: php - 使用 jquery 和 ajax 更新