PHP array tutorial _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Tags php array tutorial
PHP array usage tutorial. When using PHP for development, you need to create many similar variables either early or late. Without many similar variables, you can store data as elements in an array. When using PHP for development, you need to create many similar variables either early or late.

Without many similar variables, you can store data as elements in an array.

All elements in the array have their own IDs, so they can be easily accessed.

There are three types of arrays:

Numeric array

Array with digit ID key

Example

$ Names = array ("Peter", "Quagmire", "Joe ");

Echo $ names [1]. "and". $ names [2]. "are". $ names [0]. "'s neighbors ";

Output of the above code:

Quagmire and Joe are Peter's neighbors

Join array

Each ID key in the array is associated with a value.

$ Ages = array ("Peter" => 32, "Quagmire" => 30, "Joe" => 34 );

Echo "Peter is". $ ages ['Peter ']. "years old .";

Output of the above script:

Peter is 32 years old.

Multi-dimensional array

Array containing one or more arrays

$ Families = array

(

"Griffin in" => array

(

"Peter ",

"Lois ",

"Megan"

),

"Quagmire" => array

(

"Glenn"

),

"Brown" => array

(

"Cleveland ",

"Loretta ",

"Junior"

)

);

If this array is output, it should be similar to the following:

Array

(

[Griffin in] => Array

(

[0] => Peter

[1] => Lois

[2] => Megan

)

[Quagmire] => Array

(

[0] => Glenn

)

[Brown] => Array

(

[0] => Cleveland

[1] => Loretta

[2] => Junior

)

)

When developing PHP, you need to create many similar variables either early or late. Without many similar variables, you can store data as elements in an array ....

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.