PHP learning operations on array values

Source: Internet
Author: User
In PHP, use list to extract the values in the array, such as list ($ a, $ B) $ array.

1. value extraction
In PHP, use list to extract the values in the array, such as list ($ a, $ B) = $ array. If the number of values in the list is greater than the number of arrays, the excess values in the list are set to NULL. You can also use commas to skip the values in the array, such as list ($ a, $ B) = $ array.

2. divide arrays
To obtain the sub-array, use array_slice (array, offset, length. It returns a new subscript array starting from 0. If the subscript of the original array is a string, it seems meaningless. it is best not to use it. you can use array_splice to obtain the substring.

3. Divide the array into multiple arrays
Array_chunk can be used to divide an array into two-dimensional arrays. For details, refer to the official instructions at the link.

4. keys and values
Array_keys ($ array) to obtain an array composed of array indexes
Array_value ($ array) is used to obtain an array consisting of array values. The index is reassigned from 0.
Array_key_exists ($ key, array). check whether the element exists.
Array_splice: delete the inserted element.

5. conversion between arrays and variables
Extract (array) converts an array to a variable.
Compact () converts a variable to an array

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.