[PHP] returns to basic (Array-related functions) and array. [PHP] returns to basic (Array-related functions) and returns to array using the array_keys () function to obtain all the keys in the Array. parameters: array $ arrarray (); $ arr [one] one; $ arr [two] [PHP] returns to basic (Array-related functions) and array
Use the array_keys () function to obtain all the keys in the array. parameters: Array
$arr=array();$arr['one']="one";$arr['two']="two";$arr['three']="three";$newArr=array_keys($arr);print_r($newArr);//Array ( [0] => one [1] => two [2] => three )
Use the array_values () function to obtain all values in the array. parameters: Array
$arr=array();$arr[20]="one";$arr[30]="two";$arr[40]="three";$newArr=array_values($arr);print_r($newArr);//Array ( [0] => one [1] => two [2] => three )
Use the array_map () function to make each element call a custom function. parameter: String type function name, array
$arr=array();$arr[0]="one";$arr[1]="two";$arr[2]="three";function test($v){ return $v." Hello";}$newArr=array_map("test",$arr);print_r($newArr);//Array ( [0] => one Hello [1] => two Hello [2] => three Hello )
Use the array_merge () function to combine two arrays into one. parameters: Array and array
When the associated array is merged, the same key will be overwritten by the following array
When the index array is merged, it is connected to form a new array.
$arr=array();$arr[0]="one";$arr[1]="two";$arr[2]="three";$arr1=array();$arr[3]="taoshihan1";$arr[4]="taoshihan2";$arr[5]="taoshihan3";$newArr=array_merge($arr,$arr1);print_r($newArr);//Array ( [0] => one [1] => two [2] => three [3] => taoshihan1 [4] => taoshihan2 [5] => taoshihan3 )$arr=array("one","two","three");$arr1=array("4","5","6");$newArr=array_merge($arr,$arr1);print_r($newArr);//Array ( [0] => one [1] => two [2] => three [3] => 4 [4] => 5 [5] => 6 )
Use the ksort () function to sort by key name. Note that no new array is returned, or the original array.
$arr=array("2"=>"taoshihan2","1"=>"taoshihan1","3"=>"taoshihan3");ksort($arr);print_r($arr);//Array ( [1] => taoshihan1 [2] => taoshihan2 [3] => taoshihan3 )
Use the array_search () function to search for a key value and return the corresponding key.
$arr=array("2"=>"taoshihan2","1"=>"taoshihan1","3"=>"taoshihan3");echo array_search("taoshihan1",$arr);// 1
Struct returns to basic (Array-related functions), returns to array, and uses the array_keys () function to obtain all the keys in the array. parameters: Array $ arr = array (); $ arr ['one'] = "one"; $ arr ['two'] =...