Getting Started with PHP Basics (ii)

Source: Internet
Author: User
Tags compact getting started with php php basics sorts

Array Processing:
Compact () function: You can put a single variable, multiple variables or even arrays in an array.
$example =array ("A", "B", "C");
$example 2=compact ("D", "E", "example");

Array_combine () function: Merges two arrays into an array, and the values in the preceding array are indexed as values in the subsequent array.
$example =array ("A", "B", "C");
$example 2=array ("AA", "BB", "CC");
$example 3=array ($example, $example 2);

Application of cyclic foreach: a foreach (array name as loop inside an alias called, used to refer to the value inside an algebraic group)
Print_r () is used to display array elements.
Count () is used to calculate the number of array elements
Array_chunk ($ array name, number of partitions in each array, true/false) is used to split the array, true for the original index name, False for the 0-based index name, and the default is false;
Array_merge ($ array name 1,$ array name 2) used to merge arrays

Prev ($ array name) before an array element
Current ($ array name) array element
Next ($ array name) Next array element
End ($ array name) last array element

Sort ($ array name) to sort the values in a group in a forward direction
Rsort ($ array name) to reverse-sort values in a group
Asort ($ array name) sorts the values in a group (the relationship between the key and the value remains the same)
Ksort ($ array name) sorts the keys in the arrays (the relationship between the key and the value remains the same)
Shuffle ($ array name) random sorting of arrays
Array_reverse ($ array name) in reverse order from the original array

Reset ($ array name) resets array
Range (Low,high,step) to create an array
Array_push ($ array name, ' element name ') element can be one or more elements pressed into the element
Array_pop ($ array name) pops up the last element
Array_change_key_case ($ array name, Case_upper) change index to uppercase
ARRAY_INTERSECT_ASSOC ($ array name 1,$ array name 2) array can be multiple, calculate intersection, index also compare Array_intersect ($ array name 1,$ array Name 2) index does not participate in comparison
ARRAY_DIFF_ASSOC ($ array name 1,$ array name 2) array can be multiple, calculate only elements that appear in Array name 1, index also compares Array_diff ($ array name 1,$ array Name 2) index does not participate in comparison
ARRAY_FILP ($ array name) swaps the indexes and values in the array
Array_fill (int $start, int num, ' element ') quickly fills an array element
Array_count_values ($ array name) Number of occurrences of element values in the statistics array
Array_key_exits (index, $ array name) determines whether the index is not the array's
Array_keys ($ array name) lists all indexes in the array array_keys ($ array name, ' value ') to list the index of this value
Array_map ("function name", $ array name) all elements in an array are processed by the function, provided that the function must have parameters
In_array (' element ', $ array name) determines whether an element is inside an array
Key ($ array name) outputs the index of the current element


Regular Expressions: Preg_match ("/Expression/", "string to be captured", $capture)//Capture to a string and populate capture, this capture can be written without writing and returns a Boolean value if not written.

Getting Started with PHP Basics (ii)

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.