How can a letter be converted to a number in PHP?

To convert a letter to a number in PHP, you can use the ord() function which returns the ASCII value of a character. By subtracting the ASCII value of 'A' from the ASCII value of the letter, you can get the corresponding numerical value. This is useful for tasks like converting letters to numbers for indexing or encoding purposes.

$letter = 'A';
$number = ord($letter) - ord('A') + 1;
echo $number; // Output: 1