How can an array be used to map letters to numbers in PHP?

To map letters to numbers in PHP using an array, you can create an associative array where the keys are letters and the values are corresponding numbers. You can then access the array using the letter as the key to retrieve the mapped number. This allows for a quick and efficient way to convert letters to numbers in your PHP code.

// Create an associative array to map letters to numbers
$letterToNumber = [
    'A' => 1,
    'B' => 2,
    'C' => 3,
    // Add more mappings as needed
];

// Example usage
$letter = 'B';
$number = $letterToNumber[$letter];
echo "The letter $letter is mapped to the number $number";