I'm creating a module for a website, and to get the module parameters I do something like this:
//-- Get a parameter from the module's configuration
$company1_enable = $params->get('company1_enable');
$company1_name = $params->get('company1_name');
$company1_logo = $params->get('company1_logo');
$company1_image = $params->get('company1_image');
$company1_description = $params->get('company1_description');
But this module must support ~40 companies, meaning I would have to repeat this code 40 times, only changing the number after "company" ($company2_enable = $params->get('company2_enable');
, $company3_enable = $params->get('company3_enable');
etc. )
Is there any way to use a loop on the $params
object in order to do this more effectively?
<?php for ($i = 1; $i < 40; $i++) { if (${'company' . $i . '_enable'} === "1") { /* do something up to 40 times */ }}
. Maybe I'll end up getting the parameters manually for now, I'm just curious to see if there's a better way to handle many parameters.