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
相关文章
相关标签/搜索