当前位置:Gxlcms > PHP教程 > PHP中的array()详解

PHP中的array()详解

时间:2021-07-01 10:21:17 帮助过:38人阅读

2021041416104797647.jpg

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()详解的详细内容,更多请关注gxlcms其它相关文章!

人气教程排行