First, define the array
You can use the array () language structure to create a new array. It accepts a number of comma-separated key = value parameter pairs.
Array ([key =>] value, ...)//key can be a number or string//value can be any value
Example 1:
Copy CodeThe code is as follows:
$PHPJC = Array (
0=> ' word ',
3=> ' Excel ',
' Outlook ',
' Access ');
Print_r ($PHPJC);
?>
The output results are as follows:
Array ([0] = + word [3] + + Excel [4] = + Outlook [5] = + Access)
Example 1 defines an array, named PHPJC, with the value of the first element: Word, (description: The array is counted from 0), the second element is empty, the third element is: Excel, and the fourth and fifth elements are automatically generated later
You can create an empty array by assigning a variable an array () with no parameters, and then you can add values by using the square brackets [] syntax.
Example 2:
Copy CodeThe code is as follows:
$PHPJC = Array ();
$PHPJC [] = "one";
$PHPJC [] = "both";
echo $PHPJC [0]. "
";
echo $PHPJC [1];
The output results are as follows:
One
Both
Second, reading array elements
Use a string index (or key) to access values stored in an array
Example 3:
Copy CodeThe 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"];
http://www.bkjia.com/PHPjc/320749.html www.bkjia.com true http://www.bkjia.com/PHPjc/320749.html techarticle defining an array you can create a new array with the array () language structure. It accepts a certain number of key = value parameter pairs separated by commas. Array ([key =] value, ...)//key can be ...