PHP array Tutorial defining arrays _php Tutorial

Source: Internet
Author: User
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 ...

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