PHP array tutorial definition array _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Tags php array tutorial
PHP array tutorial defines an array. 1. you can use the array () language structure to create an array. It accepts a certain number of keyvalue parameter pairs separated by commas. Array ([key] value,...) key can be 1. define an array
You can use the array () language structure to create an array. It accepts a certain number of key => value parameter pairs separated by commas.
Array ([key =>] value,...) // key can be a number or string // value can be any value
Example 1:

The code is as follows:


$ Phpjc = array (
0 => 'word ',
3 => 'Excel ',
'Outlook ',
'Access ');
Print_r ($ phpjc );
?>


The output result is as follows:
Array ([0] => word [3] => excel [4] => outlook [5] => access)
Example 1 defines an array named phpjc. The value of the first element is word (note: The array is counted from 0), and the second element is empty, the third element is excel. The fourth and fifth elements are automatically generated later.
You can create an empty array by assigning an array () without parameters to the variable, and then add the value by using the square brackets [] syntax.
Example 2:

The code is as follows:


$ Phpjc = array ();
$ Phpjc [] = "one ";
$ Phpjc [] = "two ";
Echo $ phpjc [0]."
";
Echo $ phpjc [1];


The output result is as follows:
One
Two
II. reading array elements
Use string indexes (or keys) to access the values stored in the array
Example 3:

The code is as follows:


$ Phpjc = array ("first" => 1, "second" => 2, "third" => 3 );
Echo $ phpjc ["second"];
$ Phpjc ["third"] = 5; // change the value of the third element from "3" to "5"
Echo $ phpjc ["third"];

Struct can use the array () language structure to create an array. It accepts a certain number of key = value parameter pairs separated by commas. Array ([key =] value,...) // The key can be...

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.