Php array class and object interface usage (1/3) _ PHP Tutorial

Source: Internet
Author: User
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 :...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.