Photoshop learn the definition and padding of an array of PHP learning

Source: Internet
Author: User
Tags array definition
An array of PHP, plainly, is the associative data each array is saved in the form of [index, value]. Where the index defaults to a number starting at 0. When an index is not specified, PHP automatically generates an index starting at 0. When you specify an index, PHP starts with the next integer that you specify as the maximum positive integer for the index. If you specify a decimal number, PHP takes the integer part as an index.
In addition, there are some other small things about the array:
Array () can declare an empty array;
Array[] = $value Appends a data to an array when it exists, generates an array when the array does not exist, and appends data.
array[$index] = $value Appends or modifies a data when an array exists, generates an array when the array does not exist, and appends data.
Look at the following code:

Copy the Code code as follows:


Declaring an array
$test = Array ();
Append Data
$test 01[] = "a"; Array (0 = "a");
Append a data that is indexed as "a" with data "B"
$test 01["a"] = "B"; Array (0 = "A", "a" = "B");
To modify the data indexed to 0
$test 01[0] = "C"; Array (0 = "C", "a" = "B");
Another way to declare
$test = Array ("A", "B", "C"); Array (0 = "a", 1 = "B", 2 = "C");
Although the data for a string index is declared, the default index is 0
$test = Array ("A" = "a", "B", "C"); Array ("A" = "a", 0 = "B", 1 = "C");
The largest index in the declaration is 2, although the index is the most recent 0, but the default index is starting from 3
$test = Array (2 = "A", 0=> "B", "C"); Array (2 = "a", 0 = "B", 3 = "C");
Declares that a decimal index takes its integer part; When the index is specified, the previously declared value is modified
$test = Array ("A", 2.7=> "B", 0=> "C"); Array (0 = "C", 2 = "B");
The default index is 0, although a negative index is declared
$test = Array ( -2 = "A", "B", "C"); Array ( -2 = "a", 1 = "B", 2 = "C");
Definition of multidimensional arrays
$test = Array ($test, $test, $test 03);


Then we introduce some of the filling functions of the array, which can be found mostly from the manual, so it is simply introduced.
Range ($n, $m); Specifies the range of values. Array (2,3,4) is generated as range (2,4).
Count ($array); Gets the size of the array.
Array_pad ($array, $length, $value); Returns an array of length $length, the original insufficient array complement is $value, and the length is sufficient to return the original array.

The above describes the Photoshop learning experience PHP learning array definition and fill, including the Photoshop learning experience aspects of the content, I hope the PHP tutorial interested in a friend helpful.

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