PHP Delete array elements and delete repeated array functions this article mainly describes how to delete php array values and how to delete elements at the specified position of an array, the second section tells you how to use the array_keys letter.
Php tutorial Delete array elements and delete repeated array Functions
This article mainly talks about the deletion of php array values. It tells you how to delete an element at the specified position of an array. The second section tells you how to use the array_keys function to delete repeated elements of an array.
*/
$ 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.
$ Array1 = array (1 => "www.bkjia.com", 2 => "pineapple", 4 => "=>" banana ", 4 =>" ba le ", 5 => "=>" www.bkjia.com ");
$ Search_keys = array_keys ($ array1, "www.bkjia.com ");
Foreach ($ search_keys as $ key ){
Unset ($ array1 [$ key]);
}
Print_r ($ array1 );
/*
Expected result
Array ([2] => pineapple [4] => BA le [3] => bananas)
*/
// 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]);
}
?>