Home > Backend Development > PHP Tutorial > PHP array classes and objects interface usage (1/3)_PHP tutorial

PHP array classes and objects interface usage (1/3)_PHP tutorial

WBOY
Release: 2016-07-20 11:09:11
Original
861 people have browsed it

1. Array
The array in the PHP tutorial is actually an associative array, or a hash table. PHP does not need to declare the size of the array in advance, and can create the array by direct assignment. For example:

//The most traditional, use numbers as keys and assign values ​​

$state[0]="beijing";
$state[1]="hebei" ;
$state[2]="tianjin";

//If the key is an increasing number, you can omit it

$city[]="shanghai";
$city[]="tianjin";
$city[]="guangzhou";

//Use string as key

$capital["china"] ="beijing";
$capital["japan"]="tokyo";

It will be more convenient to use array() to create an array. You can pass the array elements to it as array parameters. You can also create associative arrays using the => operator. For example:

$p=array(1,3,5,7);

$capital=array(“china”=>”beijing”, “japan=> ;"tokyo");

array is actually a grammatical structure, not a function. Similar to array, there is also a list(), which can be used to extract the values ​​​​in the array and give Multiple variable assignments. For example:

list($s,$t)=$city;
echo $s,' ',$t;

Output result: shanghai tianjin

Note that the list method can only be used for arrays indexed by numbers.

PHP has built-in some common array processing functions. For details, please refer to the manual. Examples of commonly used functions are as follows, count or sizeof. You can get the length of the array, array_merge can merge two or more arrays, and array_push(pop) can use arrays like a stack.

1 2 3

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444810.htmlTechArticle1. Array The array in the php tutorial is actually an associative array, or a hash table. PHP does not need to declare the size of the array in advance, and can create the array by direct assignment. For example:...
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