php echo substr('hello',1,-2);-2是什么意思 为什么结果是 el

substr 是截取字符串函数 substr(string,start,length)

h    e    l     l   o 对应的针分别为

0    1    2   3  4

-4  -3  -2  -1  0



substr('hello',1,-2); start 是1  所以是从 e 开始截取长度为-2 。是截止到从后面开始数 对应-2 的字母结束 所以是 el
我的博客http://zencart.me

你可能感兴趣的:(php echo substr('hello',1,-2);-2是什么意思 为什么结果是 el)