PHP learning notes-array (1), php learning notes Array
1-1 array Definition
1. What is an array?
An array is a set of elements of the same data type arranged in a certain order. It is to name a variable of the same type with a name, and then identify the set of their variables with a number, this name is called the array name and the number is called the subscript. Each variable that makes up an array is called the component of an array, also known as an element of an array, or a subscript variable.
Syntax:
<? Php // set a variable to an empty array $ arr = array ();?>
1-2 Index Array Initialization
PHP has two types of Arrays: Index Array and associated array.
Both indexes and associations are for the keys of arrays.
An index array is an array of keys and integers in an index group. The order of keys starts from 0, and so on.
<? Php $ num = array (1, 2, 3); print_r ($ num [0]);?>
Output result: 1
1-3 index array assignment
Three methods
<? Php $ arr [0] = 1; // method 1 $ arr = array ('0' => 1); // method 2 $ arr = array (1 ); // method 3?>
1-4 access the array content
<? Php // from the array variable $ arr, the read key is 0 value $ arr = array (, 3); $ arr0 = $ arr [0]; echo $ arr0;?>