1-1 Array definition
1. What is an array?
The so-called array is a collection of elements of the same data type arranged in a certain order. It is a collection of variables that names a limited number of variables of the same type and then uses numbers to distinguish them. This name is called an array. The name and number are called subscripts. The individual variables that make up an array are called components of the array, also called elements of the array, and sometimes called subscript variables.
syntax is as follows:
<?<span>php </span><span>//</span><span>设置某个变量为一个空数组</span> <span>$arr</span>=<span>array</span><span>(); </span>?>
1-2 Index array initialization
PHP has two types of arrays: index arrays and associative arrays.
The words index and association are both for the keys of the array.
The index array is an array whose keys are integers, and the integer order of the keys starts from 0, and so on.
<?<span>php </span><span>$num</span>=<span>array</span>(1,2,3<span>); </span><span>print_r</span>(<span>$num</span>[0<span>]); </span>?>
Output result: 1
1-3 Index array assignment
3 methods
<?<span>php </span><span>$arr</span>[0]=1;<span>//</span><span>方法1</span> <span>$arr</span>=<span>array</span>('0'=>1);<span>//</span><span>方法2</span> <span>$arr</span>=<span>array</span>(1);<span>//</span><span>方法3</span> ?>
1-4 Access array content
<?<span>php </span><span>//</span><span>从数组变量$arr中,读取键为0的值</span> <span>$arr</span> = <span>array</span>(1,2,3<span>); </span><span>$arr0</span>=<span>$arr</span>[0<span>]; </span><span>echo</span> <span>$arr0</span><span>; </span>?>