PHP中的数组分为三种类型,分别是索引数组,关联数组和多维数组,接下来就带大家一起来看一看这三种数组。
1.索引数组 – 带有数字索引的数组
<?php $cars=array("nihao","shijie","Vhehe"); var_dump($cars); ?>
输出:
array(3) { [0]=> string(5) "nihao" [1]=> string(6) "shijie" [2]=> string(5) "Vhehe" }
2.关联数组 – 带有指定键的数组
<?php $age=array("a"=>"35","b"=>"37","c"=>"43"); var_dump($age); ?>
输出:
array(3) { ["a"]=> string(2) "35" ["b"]=> string(2) "37" ["c"]=> string(2) "43" }
3.多维数组 – 包含一个或多个数组的数组
<?php $fruits = array ( "fruits" => array("a" => "orange", "b" => "banana", "c" => "apple"), "numbers" => array(1, 2, 3, 4, 5, 6), "holes" => array("first", 5 => "second", "third") ); ?>
输出:
array(3) { ["fruits"]=> array(3) {["a"]=>string(6) "orange" ["b"]=>string(6) "banana" ["c"]=>string(5) "apple" } ["numbers"]=> array(6) { [0]=>int(1) [1]=>int(2) [2]=>int(3) [3]=>int(4) [4]=>int(5) [5]=>int(6) } ["holes"]=> array(3) { [0]=>string(5) "first" [5]=>string(6) "second" [6]=>string(5) "third" } }
推荐:《2021年PHP面试题大汇总(收藏)》《php视频教程》
以上就是PHP中的array()详解的详细内容,更多请关注php中文网其它相关文章!
- 上一篇:详解PHP扫描图片转点阵、二维码转点阵
- 下一篇:没有了