PHP 的数组是一种非常强大灵活的数据类型。以下是PHP数组具有的一些特性:
1、可以使用数字或字符串作为数组键值
1
|
$arr = [1 => 'ok' , 'one' => 'hello' ];
|
2、可按顺序读取数组
1
2
3
|
foreach ( $arr as $key => $value ){
echo $arr [ $key ];
}
|
3、可随机读取数组中的元素
1
2
3
4
5
|
$arr = [1 => 'ok' , 'one' => 'hello' , 'a' => 'world' ];
echo $arr [ 'one' ];
echo current( $arr );
|
4、数组的长度是可变的
1
2
3
4
5
|
$arr = [1, 2, 3];
$arr [] = 4;
array_push ( $arr , 5);
|
正是基于这些特性,我们可以使用 PHP 中的数组轻易的实现集合、栈、列表、字典等多种数据结构。

明确的学习思路能更高效的学习

点击加入该群学习
原文链接:http://www.cnblogs.com/heyue0117/p/11827830.html