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

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

> 注意：偏移量从０开始

```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'.
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://php7.shujuwajue.com/php-71x-xin-te-xing/xin-te-xing/zhi-chi-wei-fu-de-zi-fu-chuan-pian-yi-liang.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
