Converting alphabet letter to alphabet position in PHP [duplicate]



PHP Snippet 1:

ord(strtoupper($letterOfAlphabet)) - ord('A') + 1

PHP Snippet 2:

<?php
$upperArr = range('A', 'Z') ;
$LowerArr = range('a', 'z') ;
$myLetter = 't';

if(ctype_upper($myLetter)){
    echo (array_search($myLetter, $upperArr) + 1); 
}else{
    echo (array_search($myLetter, $LowerArr) + 1); 
}
?>

PHP Snippet 3:

$my_alphabet = strtoupper($my_alphabet);

PHP Snippet 4:

function offset(string $char): int {
  $abcUpper = range('A', 'Z');
  $abcLower = range('a', 'z');
  if (ctype_upper($char)) return array_search($char, $abcUpper) + 1;
  else return array_search($char, $abcLower) + 1;
}

PHP Snippet 5:

echo offset("a"); // 1

PHP Snippet 6:

function offset(string $char): int {
  $abcUpper = range('A', 'Z');
  $abcLower = range('a', 'z');
  if (ctype_upper($char)) return array_search($char, $abcUpper);
  else return array_search($char, $abcLower);
}

PHP Snippet 7:

echo offset("a"); // 0