PHP array common functions
1 --- return of element values in the array -------> array_values ();
2 --- return ----------> array_keys () from the input key in the array ();
// The return values of these two functions are also Arrays. The following table changes to an index, starting from 0.
'lumia800','brand2'=>'lumia900','brand3'=>'lumia640xl'); echo ""; var_dump(array_values($arr)); echo "
"; echo "
"; echo ""; var_dump(array_keys($arr)); echo "
";
// The Program result is as follows: 1, 2
array(3) { [0]=> string(8) "lumia800" [1]=> string(8) "lumia900" [2]=> string(10) "lumia640xl"}
array(3) { [0]=> string(6) "brand1" [1]=> string(6) "brand2" [2]=> string(6) "brand3"}
//************************************** **************************************** *********************************
3 --- check whether an element ----------> in_array (needle, haystach, [boll strict]) exists in the array;
Type and value?>
3 --- array element key names and worthy calls
"php", "lang2" => "python", "lang3" => "node");var_dump(array_flip($arr));//**********************//'php' => string 'lang1' (length=5)//'python' => string 'lang2' (length=5)//'node' => string 'lang3' (length=5)?>
4: Statistics on the number of array elements --- count ()
Array ("php5.3", "php5.4", "php5.5", "php7"), "python" => array ("python2.7", "python3.3", "python3.4 ")); $ num1 = count ($ arr1); // traverse to one-dimensional php + python = 2 $ num2 = count ($ arr1, 1 ); // one-dimensional + two-dimensional traversal 2 + 4 + 3 = 9 echo 'array $ the result of one-dimensional arr1 statistics is -'. $ num1 ."
"; Echo 'array $ arr1 multi-dimensional statistics result is-'. $ num2 ."
";?>
5: array_count_values ()
int 2 // 1 => int 3 // 'python' => int 1?>
6: delete the repeated value array_unique () in the array ()
"Php", "B" => 1, "c" => "python", "d" => 1, "e" => "php", 1 ); var_dump (array_unique ($ arr )); // ********* if there are duplicate values, keep the ********* behind the previous deletion. // 'a' => string 'php '( length = 3) // 'B' => int 1 // 'C' => string 'Python' (length = 6)?>
7: Call a custom function to process the array content array_filter ()
Int 1 // 2 => int 3 // 4 => int 5 // 6 => int 7 // 8 => int 9?>
8: array elements deserve sorting
String 'A' (length = 1) -----> minimum upper case // 1 => string 'A' (length = 1) -----> lower case followed // 2 => string 'B' (length = 1) // 3 => string 'G' (length = 1) // 4 => int 1 -------------------> max number // 5 => int 2/6 => int 3/7 => int 4/8 => int 6 rsort ($ arr ); var_dump ($ arr ); // Reverse order --- from large to small // 0 => int 6 // 1 => int 4 // 2 => int 3 // 3 => int 2 // 4 => int 1?>
9: get a value in the array based on the condition and return --- array_slice ()
10: The array is merged into a new array with the first array key name and the last array key value.
String 'Linux '(length = 5) // 'webserver' => string 'Apache' (length = 6) // 'database' => string 'mongodb '(length = 7) // 'script' => string 'php' (length = 3)?>
11: array merging, with the same element value retained after an array_merge ()
'Windows', 'B' => 'Apache', 'C' => 'mysql'); $ arr2 = array ('D' => 'Linux ', 'B' => 'nginx', 'E' => 'mongodb '); // array merging, if the two arrays have the same key name, the front var_dump (array_merge ($ arr1, $ arr2) is overwritten. // 'a' => string 'windows' (length = 7) // 'B' => string 'nginx' (length = 5) // 'C' => string 'mysql' (length = 5) // 'D' => string 'Linux '(length = 5) // 'E' => string 'mongos' (length = 7)?>
12: Array intersection and difference set array_intersect () and array_diff ()
String 'windows' (length = 7) // 2 => string 'mysql' (length = 5)?>
13: append the array content -- array_push ()
String 'windows' (length = 7) // 1 => string 'nginx' (length = 5) // 2 => string 'mysql' (length = 5) // 3 => string 'php' (length = 3) var_dump ($ arr2); // 0 => string 'Linux '(length = 5) // 1 => string 'nginx' (length = 5) // 2 => string 'mongos' (length = 7) // 3 => // array // 0 => string 'windows' (length = 7) // 1 => string 'nginx' (length = 5) // 2 => string 'mysql' (length = 5) // 3 => string 'php' (length = 3 )? >
14: remove array_pop () from the back of the array element ()
String 'Linux '(length = 5) // 1 => string 'Apache' (length = 6) // 2 => string 'ngnix' (length = 5) // ******************************** // array // 0 => string 'Linux '(length = 5) // 1 => string 'Apache' (length = 6)?>
15: remove array_pop () from the array element ()
String 'Apache' (length = 6) // 1 => string 'ngnix '(length = 5) // 2 => string 'php' (length = 3) // array // 0 => string 'ngnix '(length = 5) // 1 => string 'php' (length = 3)?>