The code is as follows: |
Copy code |
$ A = array ("red", "green", "blue", "yellow "); Count ($ a); // Get 4 Unset ($ a [1]); // deletes the second element. Count ($ a); // Get 3 Echo $ a [2]; // The array contains only three elements. In this example, we want to get the last element, but we get blue, Echo $ a [1]; // no value // Array array_splice (array input, int offset [, int length [, array replacement]) // Array_splice () is actually a function to replace array elements. However, if no replacement value is added, the elements are simply deleted. The usage of array_splice () is as follows: $ B = array ("red", "green", "blue", "yellow "); Array_splice ($ a, 1, 1 ); |
// The following describes how to comprehensively delete duplicate values and delete specified array elements.
The code is as follows: |
Copy code |
$ Array1 = array (1 => "www.111cn.net", 2 => "pineapple", 4 => "www.111cn.net", 3 => "banana", 4 => "Ba Le ", 5 => "www.111cn.net", 6 => "www.111cn.net "); $ Search_keys = array_keys ($ array1, "www.111cn.net "); Foreach ($ search_keys as $ key ){ Unset ($ array1 [$ key]); } |
Print_r ($ array1 );
/*
Expected result
Array ([2] => pineapple [4] => Ba Le [3] => bananas)
*/
The code is as follows: |
Copy code |
// Delete the function of repeating elements in the array Function delmember (& $ array, $ id) { $ Size = count ($ array ); For ($ I = 0; $ I <$ size-$ id-1; $ I ++) { $ Array [$ id + $ I] = $ array [$ id + $ I + 1]; } Unset ($ array [$ size-1]); } |
?>