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