1phpCopy<?php
2$string = "This is a string";
3
4$lastChar = $string[-1];
5echo "The last char of the string is $lastChar.";
6?>
7
1phpCopy<?php
2$string = 'This is a string';
3$lastChar = substr($string, -1);
4echo "The last char of the string is $lastChar.";
5?>
6
1phpCopy<?php
2$string = "This is a string";
3$lengthOfString = strlen($string);
4$lastCharPosition = $lengthOfString-1;
5$lastChar = $string[$lastCharPosition];
6echo "The last char of the string is $lastChar.";
7?>
8
1phpCopy<?php
2$string = "This is a string";
3$lastCharPosition = strlen($string) - 1;
4for ($x = $lastCharPosition; $x < strlen($string); $x++) {
5 $newString = $string[$x];
6}
7echo "The last char of the string is $newString.";
8?>
9