PHP array vs php constant?

I am curious if there is an increase in performance, for example, using less memory or resources in PHP for:

50 different variable parameters stored in an array, such as

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

Or 50 different variable parameters stored in a constant like this

define('facebook_api_secret', 'value here');
+5
source share
4 answers

I think this is in the field of micro-optimization . That is, the difference is small enough that you should not use one solution over another for the sake of performance. If performance was critical for your application, you would not use PHP! :-)

, . , , .

+11

, / , /.

; , , .

(, EXPLAIN ) ( APC) .

+3

50 / - - PHP. : , .

+1

. , .

For scalar values ​​(Strings, ints, etc.) that are defined once, should never change and should be accessible everywhere, you should use a constant.

If you have some kind of complicated nested configuration, for example:

$config->facebook->apikey = 'secret_key';
$config->facebook->url = 'http://www.facebook.com';

You might want to use an array or api configuration provided by one of the many frameworks ( Zend_Config is nice)

+1
source