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 脚本中有大量变量。最优性如何,将这些数据保存在单个变量中
$a = "aaa"; $b = "bbb"; $c = "ccc";
还是在关联数组中?
$mas = array("a"=>"aaa","b"=>"bbb","c"=>"ccc");
哪种方法更好?还是没有区别?
这取决于。
最好为同一上下文中的变量创建一个数组。例子:
$config = array();
您可以将所有配置变量存储到一个数组中。当然,执行脚本所需的其他变量不应该存在。