Overview, classification and declaration code demonstration of php arrays

高洛峰
Release: 2023-03-02 19:20:02
Original
912 people have browsed it

Copy code The code is as follows:
/**
** Overview of an array
1. The essence of an array: managing and operating a set of variables, processing in batches
2. Arrays are composite types
3. Data of any length can be stored in an array. It can also store any type of data
4. Arrays can complete the functions of other language data structures (linked list, queue, stack, collection class)
**
2. Classification of arrays
There are multiple units in the array, (unit Called an element)
Each element is composed of a subscript [key] and a value
When accessing an element individually, the element is accessed through the subscript [key]
1. One-dimensional array, two-dimensional array, three-dimensional array . . . . . Multidimensional array
(array of arrays means that there are other arrays in the array)

There are two kinds of arrays in 2.php
Index array: the subscript [key] is the index of the sequential integer
Associative array: the subscript is Strings as indexes
subscripts (integer, string) only have these two
*
three. Multiple declaration methods for arrays
1 Directly assign values ​​to array elements
If the index 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 one appears later subscript, if it is an assignment, the previous element will be reassigned
dWhen the mixed declaration is made, the index and association do not affect each other (the declaration of the index subscript is not affected)
2 Use the array() function

aThe default is the index array
b . If you specify subscripts for associative arrays and index arrays, use key => value
c Use "," to separate multiple members;
3 Use other function declarations
file();

*
*
*
*
**/

echo $arr[5]

//Index array
$user[]=1;
$user[9]=" Zhang San"
$user[0]=10;
$user[3]="nan";
$info=array(
"$user"=array(
//$user[0]
array("1 ","张三",10,"nan"),
//$user[1]
array("2","lisi",10,"nan"),
//$user[2]
array ("3","wangwu",10,"nan"),
),
"$score"=array(
//$user[0]
array("1","张三",10," nan"),
//$user[1]
array("2","lisi",10,"nan"),
//$user[2]
array("3","wangwu",10 ,"nan"),
),

"$connect"=array(
//$user[0]
array("1","张三",10,"nan"),
//$user [1]
array("2","lisi",10,"nan"),
//$user[2]
array("3","wangwu",10,"nan"),
),
};

$user[][]=1;
$user[][]=1;
$user[][]=1;
$user[][]=1;
$user[][ ]=1;

?>

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!