How can arrays be effectively used in PHP to map numerical values to corresponding text labels?

To map numerical values to corresponding text labels in PHP, you can use an associative array where the keys are the numerical values and the values are the corresponding text labels. This allows for easy lookup and retrieval of the text labels based on the numerical values.

// Define an associative array to map numerical values to text labels
$mapping = [
    1 => 'Label A',
    2 => 'Label B',
    3 => 'Label C'
];

// Example usage
$numericalValue = 2;
$textLabel = $mapping[$numericalValue];
echo $textLabel; // Output: Label B