Forum Moderators: coopster

Message Too Old, No Replies

Lots of variables - array or not

         

Nutter

10:39 pm on Nov 2, 2005 (gmt 0)

10+ Year Member



I'm working on a system where there will be many user definable strings - I'm estimating 100-250. These will be put in to a config file containing $variable = string type lines. Would I be better off, from a performance standpoint, to have each be a separate variable or to have an array? $string1=x, $string2=y, $string3=z - vs - $string['1']=x, $string['2']=y, $string['3']=z.

ergophobe

11:36 pm on Nov 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm pretty sure that from a performance point of view you should be best off with

- constants
- variables
- arrays
- classes

In that order. From a stability standpoint, constants are probably also the best as you'll get notices (with E_ALL) any time you try to redefine them, so you're less likely to have collisions. Variables are easiest to create and type. If you use simple variables, choose a naming convention that will make it clear that it's a config variable

$_ImAConfigVar
$im_not

For example.

Realistically, the performance differences will likely be very, very small and I would use what makes the most sense according to the logic of the script.

In other words, if using an array allows you to significantly simplify the script elsewhere, that will give you a greater performance gain.