Home  >  Article  >  Backend Development  >  Overview and classification and declaration code demonstration of php array_PHP tutorial

Overview and classification and declaration code demonstration of php array_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:13:09725browse

Copy code The code is as follows:

/**
** Overview of an array
1. The essence of an array: manage and operate a set of variables, batch processing
2. Arrays are composite types
3. Arrays can store data of any length . It can also store any type of data
4. Arrays can complete the functions of other language data structures (linked lists, queues, stacks, collection classes)
**
2. Classification of arrays
In arrays There are multiple units, (units are called elements)
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
(an array of arrays means that other arrays are stored in the array)

There are two kinds of arrays in 2.php
index array: the subscript [key] is a sequential integer Index
associative array: subscript is string as index
subscript (integer, string) There are only 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 increased from the largest 1
If the previous subscript appears later, if it is an assignment, the previous element will be reassigned
d When the mixed declaration is made, the index and association do not affect each other (it does not affect the declaration of the index subscript)
2 Use array () Function

a defaults to 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", "Zhang San",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","Zhang San",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;

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326581.htmlTechArticleCopy the code code as follows: ?php /** ** Overview of an array 1. The essence of arrays: management and Operate a set of variables and process them in batches 2. Arrays are composite types 3. Arrays can store any length of data...
Statement:
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