PHP数组与PHP常量? [英] PHP array vs PHP Constant?

查看:39
本文介绍了PHP数组与PHP常量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇,是否可以提高性能,例如在PHP中为以下目的使用更少的内存或资源:

I am curious, is there any performance gain, like using less memory or resources in PHP for:

将50个不同的设置变量保存到数组中

50 different setting variables saved into array like this

$config['facebook_api_secret'] = 'value here';

或将50个不同的设置变量保存到这样的常量中

Or 50 different setting variables saved into a Constant like this

define('facebook_api_secret', 'value here');

推荐答案

我认为这是微观优化的领域.也就是说,差异很小,以至于出于性能考虑,不值得使用一种解决方案.如果性能对您的应用至关重要,那么您就不会使用PHP!:-)

I think this is in the realm of being a micro-optimization. That is, the difference is small enough that it isn't worth using one solution over the other for the sake of performance. If performance were that critical to your app, you wouldn't be using PHP! :-)

使用更方便或更有意义的方法.我将配置数据放入常量中只是因为仅在加载配置文件后不允许更改它们,这就是常量的用途.

Use whatever is more convenient or that makes more sense. I put config data into constants if only because they shouldn't be allowed to change after the config file is loaded, and that's what constants are for.

这篇关于PHP数组与PHP常量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆