php tutorial delete array elements and delete duplicate array function This article is mainly about the deletion of the php array value Oh, tell you how to delete an array of elements at the specified location, the two tell you to use the array_keys function to delete the array of duplicate elements.
* /
$ a = array ("red", "green", "blue", "yellow");
count ($ a); // get 4
unset ($ a [1]); // Delete the second element
count ($ a); // get 3
Echo $ a [2]; // array only three elements, wanted to get the last element, but got blue,
Echo $ a [1]; / / No value
// array array_splice (array input, int offset [, int length [, array replacement]])
// array_splice () is actually a function that replaces an array element, but simply deletes the element without substitution. Here's how to use array_splice ():
$ b = array ("red", "green", "blue", "yellow");
array_splice ($ a, 1,1);
// See below a more comprehensive delete duplicate values and delete the specified array element
$ array1 = array (1 => "www.jzread.com", 2 => "Pineapple", 4 => "www.jzread.com", 3 => "Banana", 4 => "Guava", 5 => "www.jzread.com", 6 => "www.jzread.com");
$ search_keys = array_keys ($ array1, "www.jzread.com");
foreach ($ search_keys as $ key) {
unset ($ array1 [$ key]);
}
print_r ($ array1);
/ *
got the answer
array ([2] => pineapple [4] => guava [3] => banana)
* /
// 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]);
}
?>