PHP Learning Notes-arrays (7)

Source: Internet
Author: User

Array_search (value, array, bool);

Role:

Finds the existence of an array by value, returns the key

Parameters:

Value: values that need to be looked up

Array: Arrays

Bool:false Default

True when set to True to match the type and value of values

return value:

Returns False if no Return key value is found

Example: Finding a value of 5

$arr = Array (' a ' = = 5, ' b ' = ' red ', ' c ' = ' blue '); $res 1 = array_search (' 5 ', $arr); $res 2 = Array_search (' 5 ', $arr, true); Print_r ($res 1); Print_r ($res 2); Output Result: A


Array_shift (array);

Role:

Delete the first element in an array

Parameters:

Array: Arrays

return value:

Returns the array that was deleted

Example: Deleting the first parameter of an array

$arr = Array (' 1 ', ' Red ', 3, ' Blue ', ' yellow '); $res = Array_shift ($arr); Print_r ($res); Output results: 1


Array_slice (array, start, length, bool);

Role:

Intercept array

Parameters:

array; required, arrays

Start: Required to get the starting position of the array

Length: Optional, the lengths of the array to intercept, and if negative, the beginning of the end of the array

Bool:false Default Reset Key Name

True to preserve key names

return value:

Returns the intercepted array

Example: From the beginning of the array, the array that returns the last 3rd of the array

$arr = Array (' 1 ', ' a ' = = ' red ', ' c ' = = ' yellow ', ' Blue ', ' 2 ', ' a '); $res = Array_slice ($arr, 1,-2, true); Print_r ($res); Output: Array ([a] = red [c] = yellow [1] = = blue)


Array_splice (array, start, length, array2);

Role:

removes the selected array of elements and replaces the array

Parameters:

Array: Arrays

Start: The position of the array starting at the beginning of the array if it is a negative number

Length: optional, long, if negative, the position starting at the end of the array

Array2: Optional. Specifies an array with elements to insert in the original array. If there is only one element, you can set it to a string and do not need to set an array.

return value:

Returns the array that was removed

Example: Move the first element in an array and replace the other elements

$arr 1 = Array ("A" = "red", "b" = "green"); $arr 2 = Array ("A" = "purple", "b" = "yellow"); $res = Array_splice ($arr 1, 0, 1, $arr 2); Print_r ($arr 1); Print_r ($res); Output: An array of removed arrays: Array ([0] = purple [1] = yellow [b] = = green) An array of elements removed: A Rray ([A] = red)


Array_sum (array);

Role

Computes the and of the array

Parameters:

Array: Arrays

return value:

Returns the array's and

Example:

$arr = Array (1, 2, 3, 4); $res = Array_sum ($arr); Print_r ($res); Output results: 10


This article from "Snail Crawl" blog, please be sure to keep this source http://10130617.blog.51cto.com/10120617/1891318

PHP Learning Notes-arrays (7)

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.