This question is about how to produce a better code in PHP.
I've multiple arrays (5 to be exact). I've to apply the same logic to all of them. How can I avoid to duplicate the code for all of them ?
$cpus = getCPUs(); // Get array 1 dimension with key
$rams = getRAMs(); // Get array 1 dimension with key
I mean, the code inside, I just have to create a function. That's OK. But I still have to declare one foreach loop for each array...
Is there a way to avoid that ? It's like to have my foreach loop parameters from variables.
foreach ($cpus as $key_cpu => &$cpu) {
// FUNCTION XXX
}
foreach ($rams as $key_ram => &$ram) {
// FUNCTION XXX
}
Regards