1phpCopy<?php
2$string = "This is a string";
3
4$lastChar = $string[-1];
5echo "The last char of the string is $lastChar.";
6?>
71function getLastWord($string)
2 {
3 $string = explode(' ', $string);
4 $last_word = array_pop($string);
5 return $last_word;
6 }1phpCopy<?php
2$string = 'This is a string';
3$lastChar = substr($string, -1);
4echo "The last char of the string is $lastChar.";
5?>
6