PHP Array (i)

Source: Internet
Author: User
The array index of PHP is starting at 0 instead of 1.

$states [0]//ordinary array can be used as the key $states[' AA '//correlation array with a key value pair to call $states[' AA ' [' AAA ']//multiple arrays can be called in this way

    1. Whether an associative array or a numeric key is used in PHP is dependent on an array pointer's property, the array pointer is like a bookmark that tells you the array bit being checked.

    2. Instead of manipulating array pointers directly, you use built-in language attributes or functions to iterate through the array

    3. This means that in PHP, all the array management methods are actually manipulating the array pointers, only the method of manipulating pointers is PHP built-in or is encapsulated by the function.

Create an array

Directly create

$states [0] = 1; $states [] = 1; $states [' AA '] = 1;

Creating arrays with Array ()

$languages = Array (' Spain ' = ' Spanish ', ' ireland ' = ' 中文版 ');

Extracting an array with list

File Users.txt Content a|b|c$users = fopen (' Users.txt ', ' R '), while ($line = Fgets ($users, 4096)) {  list ($name, $sex, $age) = Explode ("|", $line);   by explode | As the delimiter, and then divided into 3 parts, and then use list to add these 3 parts into 3 variables}echo $name; echo $sex; Echo $age;

Using range to generate an array

$test = range (1,6); Generates an array of 6 elements with a value of 1 to 6 $test = range (1,10,2); The third parameter is the step size, which is probably the meaning of the interval, which generates 1 3 5 .... Value at Interval of 2

Test array

Test with Is_array, return true and False

Print array

Use Print_r to print

Print_r ($states); Traversing a printed array
  • Related Article

    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.