Home > Backend Development > PHP Tutorial > PHP study notes-array (1), php study notes array_PHP tutorial

PHP study notes-array (1), php study notes array_PHP tutorial

WBOY
Release: 2016-07-13 10:00:15
Original
961 people have browsed it

PHP study notes-array (1), php study notes array

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>?>
Copy after login

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>?>
Copy after login

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>
?>
Copy after login

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>?>
Copy after login


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/975063.htmlTechArticlePHP study notes - array (1), php study notes array 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, which is a finite...
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