Copy Code code as follows:
<?php
/*
* One, an overview of the array
* 1. The nature of the array: manage and manipulate a set of variables, batch processing
* 2. Composite type when array (can store multiple)
* 3. An array can store data of any length, or it can store any type of data
* 4. Array can complete other language data structure function (linked list, queue, Stack, collection Class)
*
*
*
* Two, the classification of the array
* There are multiple units in the array (unit called element)
* each element (subscript [key] and value)
* When accessing elements, the elements are accessed by subscript (key)
* 1. One-dimensional array, two-dimensional array, three-dimensional array ... Multidimensional arrays
* (Array of arrays, in which there are other arrays in the array)
* There are two kinds of arrays in 2.PHP
* Index Array: Subscript is an index of sequential integers
* Associative array: Is the subscript is a string as an index
*
* Subscript (integer, string) only these two kinds of
*
*
* Three, the array of multiple declaration methods
*
* 1. Assignment declaration directly to the array element
* If index subscript is not given, it will be indexed from 0
* If you give the index subscript, the next will be 1 from the maximum start
* If the previous subscript appears, if the assignment is to be assigned to the previous element to be assigned a value
* Mixed declarations, indexes and associations do not affect each other (without affecting the declaration of index subscript)
*
* 2. Use the array () function to declare
* Default is indexed array
* If you specify subscript for associative and indexed arrays, use the key => value
* use "," split between multiple members
* 3. Use other function declarations
*
*
*
*
*/
Indexed arrays
$user [0]=1;//User number
$user [1]= "Zhangsan";//user name
$user [2]=10;//Age
$user [3]= "Nan";//gender
Echo ' <pre> ';
Print_r ($user);
Echo ' </pre> ';
Associative arrays
$user ["id"]=1;
$user ["Name"]= "Zhangsan";
$user ["Age"]=10;
$user ["Sex"];
$user [' Age ']=90;//assignment
echo $user ["name"];//output
Declaring an array using array ()
$user =array (1, "Zhangsan", "Nan");
Declaring an associative array using array ()
$user =array ("id" =>1, "name" => "Zhangsan", "Age" =>10, "Sex" => "Nan");
Declare a multidimensional array (multiple records) to hold multiple user information records in a table
$user =array (
Use $user[0] to invoke this line, such as calling names in this record, $user [0][1]
Array (1, "Zhangsan", Ten, "Nan"),
Use $user[1] to invoke this line, such as calling names in this record, $user [1][1]
Array (2, "Lisi", "NV")
);
Arrays hold multiple tables, each table has more than one record
$info =array (
"User" =>array (
Array (1, "Zhangsan", Ten, "Nan"),
Array (2, "Lisi", "NV")
),
"Score" =>array (
Array (1,90,80,70),
Array (2,60,40,70)
)
);
echo $info ["score"][1][1];//output 60,
?>