What will be more performant and ressource friendlier?
To use
$array1=Array();
$array2=Array();
$array3=Array();
or:
$arr=Array();
$arr[] = Array();
$arr[] = Array();
$arr[] = Array();
And what is better to handle in the code when maintenance is required?
I have to handle about 2800 different arrays so the performance is very important.
Maintainability usually depends on what you're storing in the arrays and how you're accessing them...
If there are logical groupings/sets and you'd ever want to loop through the arrays ($array1
, $array2
, etc...) then make them nested associative arrays.
$Config = array(
'Database' => array(
'Host'=>"10.0.0.1",
'user'=>"root"
),
'API' => array(
'Endpoint'=>"http://example.com/"
),
);
If they're totally different, then it's really a judgement call
An array of arrays may be marginally lighter on memory but to be honest, with PHP the difference is going to be so small, it's not really worth wasting time worrying about until you get a performance bottleneck - and when you do, I suspect it won't be with how you declare your arrays