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
相關文章
相關標籤/搜索