PHP Delete array element and delete duplicate array function _php Tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.