I have a question, what is more faster ...
Advantages over variables An array is considered to be a homogenous collection of data. Here the word collection means that it helps in storing multiple values which are under the same variable. For any purpose, if the user wishes to store multiple values of a similar type, an array is the best option that can be used.
Note: Only the difference in using [] or array() is with the version of PHP you are using. In PHP 5.4 you can also use the short array syntax, which replaces array() with [].
An array variable is one variable; it is not many variables.
There is no max on the limit of an array. There is a limit on the amount of memory your script can use. This can be changed in the 'memory_limit' in your php.
Just a try :)
With 5 variables
$myvar1 = 'hello'; $myvar2 = 'hello'; $myvar3 = 'hello'; $myvar4 = 'hello'; $myvar4 = 'hello'; print_r(memory_get_usage());
Resut : 618600
with 5 array keys
$myvar = array(); $myvar['var1'] = 'hello'; $myvar['var2'] = 'hello'; $myvar['var3'] = 'hello'; $myvar['var4'] = 'hello'; $myvar['var5'] = 'hello'; print_r(memory_get_usage());
Resut : 620256
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With