> 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-70x-xin-te-xing/qi-ta-te-xing-he-bian-geng/chang-liang-shu-zu.md).

# 常量数组

从PHP5.6开始，常量数组可以使用const关键词来声明，代码如下：

```php
const ANIMALS = ['dog', 'cat', 'bird'];
```

与普通数组做一个对比,代码如下:

```php
const ANIMALS = ['aa' => 'dog', 'cat', 'bird'];
echo ANIMALS[0] . '<br>';
echo ANIMALS['aa'] . '<br>';

$amimals =  ['aa' => 'dog', 'cat', 'bird'];
echo $amimals[0] . '<br>';
echo $amimals['aa'] . '<br>';
```

输出结果:

```
cat
dog
cat
dog
```

在PHP7中常量数组也可以通过define函数来初始化。代码如下：

```php
define('ANIMALS', [
    'dog',
    'cat',
    'bird'
]);

echo ANIMALS[1]; // 输出 "cat"
```

补充

```php
define('ANIMALS', [
    'aa' => 'dog',
    'cat',
    'bird'
]);

echo ANIMALS[1]; // 输出 "bird"
echo ANIMALS['aa']; // 输出 "dog"
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://php7.shujuwajue.com/php-70x-xin-te-xing/qi-ta-te-xing-he-bian-geng/chang-liang-shu-zu.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
