Php definition array and usage example (php array definition method) _ PHP Tutorial

Source: Internet
Author: User
Tags array definition php definition
Php defines arrays and usage examples (php array definition method ). This is an example of php on the array. it briefly describes the basic use of the array. in the example, a comment is added to copy the code as follows :? Php defines a string array $ fruit. this is an example of the php array. it briefly describes the basic use of the array, and adds a comment in the example.

The code is as follows:


// Define a string array
$ Fruit = array (\ "apple \", \ "orange \");
// Reference the array value
$ Fruit [0]; // indicates the value of apple
$ Fruit [1]; // indicates the value of orange.
// It is worth noting that the index of the array starts from 0. anyone who has learned c and java knows it.

// Define a numeric array
$ Number = array (, 5); // The value of the referenced array is the same as that

// Define a conforming array
$ Mix = array (1, \ "example \", \ "hello \", 2.5); // The value of the referenced array is the same as that

// You can also use the key-value method to define an array.
$ Ex = array (\ "a \" => \ "fruit \", \ "B \" => \ "car \");
// You can reference it like this
$ Ex [\ "a \"]; // the corresponding value is fruit.
$ Ex [\ "B \"]; // the corresponding value is the car
// You can also create an array with the key-value type.
?>

The pipeline code is as follows :? Php // define a string array $ fruit =...

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.