Home > Article > Backend Development > Detailed explanation of array() in PHP
Arrays in PHP are divided into three types, namely index arrays, associative arrays and multi-dimensional arrays. Next, I will take you to take a look at these three types of arrays.
1. Index array - array with numeric index
<?php $cars=array("nihao","shijie","Vhehe"); var_dump($cars); ?>
Output:
array(3) { [0]=> string(5) "nihao" [1]=> string(6) "shijie" [2]=> string(5) "Vhehe" }
2. Associative array - an array with specified keys
<?php $age=array("a"=>"35","b"=>"37","c"=>"43"); var_dump($age); ?>
Output:
array(3) { ["a"]=> string(2) "35" ["b"]=> string(2) "37" ["c"]=> string(2) "43" }
3. Multidimensional array - contains a Or an array of multiple arrays
<?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") ); ?>
Output:
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" } }
Recommendation: 《2021 Summary of PHP Interview Questions (Collection)》《php video tutorial》
The above is the detailed content of Detailed explanation of array() in PHP. For more information, please follow other related articles on the PHP Chinese website!