This article mainly introduces the php array definition and use example (php array definition method). If you need a php array definition, refer to this example, this section briefly describes the basic use of arrays. annotations are added 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 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.