How can the logic for counting active modules be improved in the provided code snippet to avoid unnecessary complexity?

The logic for counting active modules can be improved by simplifying the conditional check. Instead of checking if the module is equal to 'active' and then incrementing the count, we can directly check if the module is 'active' and only then increment the count. This will reduce unnecessary complexity and make the code more readable.

$modules = [
    'module1' => 'active',
    'module2' => 'inactive',
    'module3' => 'active',
    'module4' => 'active',
];

$activeModuleCount = 0;

foreach ($modules as $module) {
    if ($module === 'active') {
        $activeModuleCount++;
    }
}

echo "Number of active modules: " . $activeModuleCount;