Php array class and object interface usage (13 ). 1. the array php Tutorial array is actually an associated array, or a hash table. Php does not need to declare the array size in advance. you can create an array by directly assigning values. Example: 1. array
The array in the php Tutorial is actually an associated array, or a hash table. Php does not need to declare the array size in advance. you can create an array by directly assigning values. For example:
// The most traditional method: Use numbers as keys and assign values.
$ State [0] = "beijing ";
$ State [1] = "hebei ";
$ State [2] = "tianjin ";
// If the key is an incremental number, it can be omitted
$ City [] = "shanghai ";
$ City [] = "tianjin ";
$ City [] = "guangzhou ";
// Use a string as the key
$ Capital ["china"] = "beijing ";
$ Capital ["japan"] = "tokyo ";
It is more convenient to use array () to create an array. you can use an array element as an array parameter and use the => operator to create an associated array. For example:
$ P = array (1, 3, 5, 7 );
$ Capital = array ("china" => "beijing", "japan =>" tokyo ");
Array is actually a syntax structure, not a function. Similar to array, there is also a list (), which can be used to extract values from the array and assign values to multiple variables. For example:
List ($ s, $ t) = $ city;
Echo $ s, '', $ t;
Output result: shanghai tianjin
Note: The list method can only be used for arrays indexed by numbers.
Php has built-in some common array processing functions. for details, refer to the manual. Examples of common functions are as follows. count or sizeof can get the length of the array. array_merge can combine two or more arrays. array_push (pop) can use arrays like stacks.
1 2 3
Http://www.bkjia.com/PHPjc/444810.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/444810.htmlTechArticle1. array php Tutorial array is actually an associated array, or a hash table. Php does not need to declare the array size in advance. you can create an array by directly assigning values. Example :...