How can a beginner modify PHP code to display group names instead of group numbers in the output?
To display group names instead of group numbers in the output, a beginner can modify the PHP code by creating an associative array where the keys are group numbers and the values are group names. Then, when iterating through the groups in the code, replace the group numbers with their corresponding group names using the associative array.
<?php
// Define an associative array mapping group numbers to group names
$groupNames = array(
1 => 'Admin',
2 => 'Users',
3 => 'Guests'
);
// Original code to display group numbers
$groups = array(1, 2, 3);
foreach ($groups as $group) {
echo "Group: " . $group . " - " . $groupNames[$group] . "<br>";
}
?>