PHP Arrays Using tutorial _php Tutorial

Source: Internet
Author: User
You will need to create many similar variables in the process of using PHP for development, either early or late.

Without a lot of similar variables, you can store the data in an array as an element.

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

There are three types of arrays:

Array of values

An array with a numeric ID key

Example

$names = Array ("Peter", "Quagmire", "Joe");

echo $names [1]. "and". $names [2]. "Is". $names [0]. "' s Neighbors";

The output of the above code:

Quagmire and Joe are Peter ' s neighbors

Associative arrays

Each ID key in the array associates a value

$ages = Array ("Peter" =>32, "quagmire" =>30, "Joe" =>34);

echo "Peter is". $ages [' Peter ']. "Years old.";

Output from the above script:

Peter is the years old.

Multidimensional arrays

An array that contains one or more arrays

$families = array

(

"Griffin" =>array

(

"Peter",

"Lois",

"Megan"

),

"Quagmire" =>array

(

"Glenn"

),

"Brown" =>array

(

"Cleveland",

"Loretta",

"Junior"

)

);

If you output this array, it should look something like this:

Array

(

[Griffin] = = Array

(

[0] = Peter

[1] = Lois

[2] = Megan

)

[Quagmire] = = Array

(

[0] = Glenn

)

[Brown] = Array

(

[0] = Cleveland

[1] = Loretta

[2] = Junior

)

)

http://www.bkjia.com/PHPjc/822520.html www.bkjia.com true http://www.bkjia.com/PHPjc/822520.html techarticle you will need to create many similar variables in the process of using PHP for development, either early or late. Without a lot of similar variables, you can store the data in an array as an element. ...

  • 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.