Files
freeCodeCamp/guide/chinese/php/arrays/index.md
2018-10-16 21:32:40 +05:30

44 lines
1.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Arrays
localeTitle: 数组
---
## 数组
### 数组类型
在PHP中有三种类型的数组索引数组关联数组和多维数组。
### 索引数组示例
索引数组按索引号访问对象。
```PHP
<?php
$freecodecamp = array("free", "code", "camp");
```
`$freecodecamp[0]`将返回`"free"` `$freecodecamp[1]`将返回`"code"` `$freecodecamp[2]`将返回`"camp"`
### 关联数组示例
关联数组按键名访问对象。
```PHP
<?php
$freecodecamp = array("free"=>"0","code"=>"1","camp"=>"2");
```
`$freecodecamp['free']`将返回“0” `$freecodecamp['code']`将返回“1” `$freecodecamp['camp']`将返回“2”
### 多维数组示例
多维数组是包含其他数组的数组。
```PHP
<?php
$freecodecamp = array(array("free"=>"0","code"=>"1","camp"=>"2"),array("free"=>"0","code"=>"1","camp"=>"2"),array("free"=>"0","code"=>"1","camp"=>"2"));
```
#### 更多信息:
* [php.net数组手册](https://secure.php.net/manual/en/language.types.array.php)