Getting the Last Character of a String in PHP


Access the last character of a string by using negative indexing with substr().

Source Code

$str = "Hello";
echo substr($str, -1); // Outputs: "o"
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments