What are the best practices for efficiently extracting the first character of a variable in PHP?

When extracting the first character of a variable in PHP, it is best to use the substr() function with a start position of 0 and a length of 1. This will efficiently retrieve the first character without unnecessary overhead.

// Variable containing a string
$myString = "Hello";

// Extracting the first character
$firstChar = substr($myString, 0, 1);

// Output the first character
echo $firstChar;