Php 分别返回字符串的最后3位数字

Php 分别返回字符串的最后3位数字,php,Php,假设我有以下字符串: $exampleString = "8b1a9953c4611296a827abf8c47804d7"; 如何分别返回此字符串的最后3位数字 我的意思是我想要3个变量,比如说,$thirdLastCharacter,$secondLastCharacter和$lastCharacter,在这种情况下,它们等于“4”,“d”和“7” 最后一个很简单,我可以这么做: $lastCharacter = substr($exampleString,-1); 这会给我“7”,但

假设我有以下字符串:

$exampleString = "8b1a9953c4611296a827abf8c47804d7"; 
如何分别返回此字符串的最后3位数字

我的意思是我想要3个变量,比如说,
$thirdLastCharacter
$secondLastCharacter
$lastCharacter
,在这种情况下,它们等于“4”,“d”和“7”

最后一个很简单,我可以这么做:

$lastCharacter = substr($exampleString,-1);
这会给我“7”,但我不确定我会如何为其他人做到这一点

我怎么能做到这一点呢?

我想出来了

$lastCharacter = substr($exampleString,-1);

$secondLastCharacter = $exampleString[strlen($exampleString)-2];

$thirdLastCharacter = $exampleString[strlen($exampleString)-3];
我明白了

$lastCharacter = substr($exampleString,-1);

$secondLastCharacter = $exampleString[strlen($exampleString)-2];

$thirdLastCharacter = $exampleString[strlen($exampleString)-3];
好了

$exampleString = "8b1a9953c4611296a827abf8c47804d7";

// returns d
$secondLastCharacter = substr($exampleString, -2, 1);

// returns 4
$thirdLastCharacter = substr($exampleString, -3, 1);

// returns 7 
$lastCharacter = substr($exampleString, -1);
好了

$exampleString = "8b1a9953c4611296a827abf8c47804d7";

// returns d
$secondLastCharacter = substr($exampleString, -2, 1);

// returns 4
$thirdLastCharacter = substr($exampleString, -3, 1);

// returns 7 
$lastCharacter = substr($exampleString, -1);

$last character=substr($exampleString,-3)这里的检查函数我认为你没有正确理解我的问题。所以你需要为每个变量输入不同的字符吗?是的,这就是我需要的。
$last haracter=substr($exampleString,-3)这里的检查函数我认为你没有正确理解我的问题。所以你需要为每个变量输入不同的字符吗?是的,这就是我需要的。