PHP Delete array element and delete duplicate array function This article is mainly about the deletion of PHP array values Oh, tell you how to remove an array to specify the location of the element, the most two tells you to use the Array_keys letter
PHP Tutorial Delete array elements and delete duplicate array functions
This article is mainly about the deletion of the PHP array value Oh, tell you how to remove an array to specify the location of the element, the most two tells you to use the Array_keys function to delete the array of repeating 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]; There are only three elements in the array, and I wanted to get the last element, but I got blue,
echo $a [1]; No value
Array array_splice (array input, int offset [, int length [, array replacement]])
Array_splice () is actually a function of replacing an array element, but it is simple to delete an element without replacing it. The following is the use of Array_splice ():
$b =array ("Red", "green", "blue", "yellow");
Array_splice ($a, 1, 1);
Let's look at a more comprehensive delete duplicate value and delete the specified array element
$array 1 = Array (1 = "www.bkjia.com", 2 = "Pineapple", 4 = "=" Banana ", 4 =" Pattaya ", 5 =" = "www.bkjia.com");
$search _keys = Array_keys ($array 1, "www.bkjia.com");
foreach ($search _keys as $key) {
unset ($array 1[$key]);
}
Print_r ($array 1);
/*
Get results
Array ([2] = pineapple [4] = [3] = banana)
*/
//delete function of repeating element in 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]);
}
?>
http://www.bkjia.com/PHPjc/445431.html www.bkjia.com true http://www.bkjia.com/PHPjc/445431.html techarticle php Delete array element and delete duplicate array function This article is mainly about the deletion of the PHP array value Oh, tell you how to remove an array to specify the location of the element, the most two to tell you Lee ...