> For the complete documentation index, see [llms.txt](https://php7.shujuwajue.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://php7.shujuwajue.com/php-71x-xin-te-xing/xin-te-xing/zhi-chi-wei-fu-de-zi-fu-chuan-pian-yi-liang.md).

# 支持为负的字符串偏移量

现在所有支持偏移量的字符串操作函数 都支持接受负数作为偏移量，包括通过\[]或{}操作字符串下标。在这种情况下，一个负数的偏移量会被理解为一个从字符串结尾开始的偏移量。

> 注意：偏移量从０开始

```php
var_dump("abcdef"[2]);  //c
var_dump("abcdef"[-2]);  //e
var_dump(strpos("aabbcc", "b", -3)); // 3
```

负字符串和数组偏移现在也支持字符串中简单的变量分析语法。

```php
<?php
$string = 'bar';
echo "The last character of '$string' is '$string[-1]'.\n";
?>
```

以上例程会输出：

```
The last character of 'bar' is 'r'.
```
