1

Which option is better to save server resources: Array with many values or many variables, each with one value?

Latter the array values will plan to use like this: array($input[0], array($input[3], array($input[10].

Variables: $input0, $input0, $input10.

Which option is better to save server resources (is it worth to pay attention at all)?

user2232696
  • 494
  • 2
  • 6
  • 14
  • 1
    and what if you have 100 variables? you'll write them one-by-one? –  May 08 '13 at 05:28
  • So as understand need to use array? Is it not as much question about server resources but question about design of code and fast/not fast coding? – user2232696 May 08 '13 at 05:34
  • Definitely use arrays. – Dogbert May 08 '13 at 05:35
  • About saving server resources: [Is micro-optimization worth the time?](http://stackoverflow.com/q/3470990/1409082). Unless you have proof that your script is using too many resources, you shouldn't bother and choose the option that will make things easier for you. – Jocelyn May 29 '13 at 17:06

1 Answers1

1

If you plan on referring to a set of variables as a group you would need an array. Other options would be variable variables or string interpolation such as

$input0 = 'a';
$input1 = 'b';
$input2 = 'c';

// Note you must know the number of 'input' variables ahead of time...
for($i=0; $i<3; $i++)
  echo "$input${i}";

Nothing short of atrocious IMO.

quickshiftin
  • 66,362
  • 10
  • 68
  • 89