Array_key_exists (Key,array);
Role:
Whether there is a key in array arrays
Return:
BOOL exists return True, there is no return false
Example: whether the name exists in the array
$arr = Array (' name ' = = ' char ', ' age ' = +, ' sex ' = ' f '); if (array_key_exists (' name ', $arr)) {echo ' name exists ';} else {echo ' name does not exist ';} Output: Name exists
Array_keys (array, value, BOOL);
Role:
Gets the key value in the array
Parameters:
Array: Arrays
Value: Optional, specifying the value in the array
BOOL: Optional default not false, used with value values, default does not need to match the type of value, true matches the type.
return value:
Returns an array containing the key
Example:
$arr = Array (' name ' = = ' char ', ' age ' = +, ' sex ' = ' f '); $keys = Array_keys ($arr); Gets the key value of the array $key 1 = Array_keys ($arr, ' 21 '); Gets the value 21 for the key $key 2 = Array_keys ($arr, ' + ', true); Gets the key value of value 21, and value is the string Print_r ($keys); Print_r ($key 1); Print_r ($key 2); Output: Array ([0] + = name [1] = age [2] = = Sex) array ([0] = age) Array ()
Array_map (string, array);
Role:
With a custom function, each parameter in the array is processed and returned
Parameters:
String: Name of function
Array: Arrays
return value:
Returns the new array
Example: Multiply each parameter of an array by 2
function MyFunction ($v) {return $v *;} $arrOne = Array (' A ' =>1, ' b ' = = 2, 3, 4, 5); $res = Array_map (' myFunction ', $arrOne); Print_r ($res); Output: Array ([A] = 2 [b] = 4 [0] = 6 [1] = 8 [2] = 10)
Array_merge (Array1, array2);
Role:
Merging one or more arrays
Parameters:
Array1: Merged array 1
Array2: merged array 2
return value:
The merged array
Example:
$arrOne = Array (' a ' = = ' Blue ', ' b ' = ' yellow '); $arrTwo = Array (' a ' = = ' red ', ' d ' = ' purple '); $res = Array_merge ($arrOne, $ARRTWO); Print_r ($res); Output: Array ([a] = red [b] = yellow [d] = purple)
Array_merge_recursive (Array1, arrray2);
Role:
Recursive merging of multiple arrays, unlike Array_merge (), which does not overwrite when processing the value of the same key name
Parameters:
Array1: Merged array 1
Aray2: merged array 2
return value:
The merged array
Example:
$arrOne = Array (' a ' = = ' Blue ', ' b ' = ' yellow '); $arrTwo = Array (' a ' = = ' red ', ' d ' = ' purple '); $resRe = Array_merge_recursive ($arrOne, $ARRTWO); Print_r ($resRe); Output: Array ([a] = = Array ([0] = blue [1] = red) [b] = Yellow [d] = purple)
This article from "Snail Crawl" blog, please be sure to keep this source http://10130617.blog.51cto.com/10120617/1890338
PHP Learning Notes-arrays (4)