Php: array data type instances

Source: Internet
Author: User
An array is a collection of data. it organizes a series of data to form an operable whole. Arrays can contain a lot of data, such as scalar arrays, arrays, objects, resources, and other syntax structures supported by PHP. This chapter describes the two types of compound data in PHP. Array

What is array)

An array is a collection of data. it organizes a series of data to form an operable whole. Arrays can contain a lot of data, such as scalar arrays, arrays, objects, resources, and other syntax structures supported by PHP.

Each data in an array is called an element. the element consists of an index (key name) and a value. The index of an element can be composed of digits or strings. The value of an element can be of multiple data types, the syntax format for defining arrays is as follows:

You can use the array () language structure to create an array. Each array element is separated by commas (,).

$array=('value1','value2'......)

Or

$array[key]='value'

Or

$array=array(key1=>value1,key2=>value2......)

Parameters:

The parameter key is the subscript of the array element, and the value is the element corresponding to the array subscript.

You can use the short array definition syntax from 5.4 and replace array () ().

The previously defined array is like this.

  "bar",   "bar" => "foo",);

// From PHP 5.4

$array = [   "foo" => "bar",   "bar" => "foo",];?>

Array definition example

The following are all in the correct format.

 'Php', 1 => 'Chinese net'); $ arr3 [0] = 'tmpname';?>

After an array, the number of elements in the array can be changed. as long as an array is assigned a value, the length of the array is automatically increased. For more information about arrays, see The php Array (Array) topic.
In the next section, we will explain the "object" of the two composite data types in PHP"

The above is php: detailed description of the array (array) data type instance. For more information, see other related articles in the first PHP community!

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.