How can arrays be effectively used in PHP to map numerical values to corresponding text values for display purposes?
To map numerical values to corresponding text values for display purposes in PHP, you can use an associative array where the keys are the numerical values and the values are the corresponding text values. This allows for easy lookup and retrieval of the text value based on the numerical key.
// Define an associative array to map numerical values to text values
$valueMapping = [
1 => 'One',
2 => 'Two',
3 => 'Three',
];
// Example usage: retrieve text value for numerical key
$numValue = 2;
$textValue = $valueMapping[$numValue];
echo $textValue; // Output: Two