Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 PHP 中,我看到了以下类型的编码:
my_array[] = "fish"; my_array[] = "book"; my_array[] = "chair";
其他时候我看到这样做:
my_array = array(); my_array[] = "fish"; my_array[] = "book"; my_array[] = "chair";
像上面那样使用 array() 在 PHP 中“定义”一个数组的目的是什么?这是一个好习惯,如果是这样,为什么?
确保在使用变量之前定义变量是一种很好的做法。
您不必在 PHP 中声明变量。这只是一种更好的做法,可以提高可读性,并且可以使用您以后可能使用的函数防止数组出现一些错误..