Home > Backend Development > PHP Tutorial > photoshop learning forum php learning array declaration

photoshop learning forum php learning array declaration

WBOY
Release: 2016-07-29 08:45:26
Original
1063 people have browsed it

Copy code The code is as follows:


/*
* 1. Overview of arrays
* 1. The essence of arrays: manage and operate a set of variables, batch processing
* 2. Arrays Composite type (can store multiple)
* 3. Arrays can store data of any length and any type of data
* 4. Arrays can complete the functions of other language data structures (linked lists, queues, stacks, sets Class)
*
*
*
* 2. Classification of arrays
* There are multiple units in the array, (units are called elements)
* Each element (subscript [key] and value)
* Single access element Sometimes, elements are accessed through subscripts (keys)
* 1. One-dimensional array, two-dimensional array, three-dimensional array. . . Multidimensional array
* (an array of arrays means that other arrays are stored in the array)
* 2. There are two types of arrays in PHP
* Index array: the subscript is the index of a sequential integer
* Associative array: it is the subscript It is a string as an index
*
* There are only two subscripts (integer, string)
*
*
* 3. Multiple declaration methods of arrays
*
* 1. Directly assign a value to the array element declaration
* If the index If the subscript is not given, the sequential index will start from 0
* If the index subscript is given, the next one will be incremented by 1 from the largest
* If the previous subscript appears later, if it is an assignment, it will be the previous element Reassignment
* When mixed declaration, index and association do not affect each other (does not affect the declaration of index subscript)
*
* 2. Use the array() function to declare
* The default is an index array
* If specified for an associative array and an index array Subscript, use key => value
* Use " , " to split
* between multiple members 3. Use other function declarations
*
*
*
*
*/
//Index array
$user[ 0]=1;//User serial number
$user[1]="zhangsan";//User name
$user[2]=10;//Age
$user[3]="nan";//Gender
echo '

'; <br>print_r($user); <br>echo '
';
//Associative array
$user["id"]=1;
$user["name"] ="zhangsan";
$user["age"]=10;
$user["sex"];
$user["age"]=90;//Assignment
echo $user["name"];/ /Output
//Use array() to declare an array
$user=array(1,"zhangsan",10,"nan");
//Use array() to declare an associative array
$user=array("id"= >1,"name"=>"zhangsan","age"=>10,"sex"=>"nan");
//Declare a multi-dimensional array (multiple records) to save in a table Multiple user information records
$user=array(
//Use $user[0] to call this line, such as calling the name in this record, $user[0][1]
array(1,"zhangsan" ,10,"nan"),
//Use $user[1] to call this line, for example, call the name in this record, $user[1][1]
array(2,"lisi",20," nv")
);
//Array saves multiple tables, each table has multiple records
$info=array(
"user"=>array(
array(1,"zhangsan",10,"nan "),
array(2,"lisi",20,"nv")
),
"score"=>array(
array(1,90,80,70),
array(2,60,40 ,70)
)
);
echo $info["score"][1][1];//Output 60,
?>

The above introduces the array declaration of photoshop learning forum and php learning, including the content of photoshop learning forum. I hope it will be helpful to friends who are interested in PHP tutorials.

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