Home > Backend Development > PHP Tutorial > Detailed explanation of array() in PHP

Detailed explanation of array() in PHP

autoload
Release: 2023-04-09 21:08:01
Original
6616 people have browsed it

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);

?>
Copy after login

Output:

array(3) { [0]=> string(5) "nihao" [1]=> string(6) "shijie" [2]=> string(5) "Vhehe" }
Copy after login

2. Associative array - an array with specified keys

<?php
$age=array("a"=>"35","b"=>"37","c"=>"43");
var_dump($age);
?>
Copy after login

Output:

array(3) { ["a"]=> string(2) "35" ["b"]=> string(2) "37" ["c"]=> string(2) "43" }
Copy after login

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")
);
?>
Copy after login

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"
  }
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template