Php deletes the specified array element method_php tutorial

Source: Internet
Author: User
Php deletes the specified array element method. The following two efficient methods for deleting array elements are provided. you can delete the elements by specifying the deletion option. For more information, see php.net. The following code provides two efficient methods to delete array elements. you can delete the elements by specifying the deletion option. For more information, see php.net.
The code is as follows:

Function deleteFromArray (& $ array, $ deleteIt, $ useOldKeys = FALSE)
{
$ TmpArray = array ();
$ Found = FALSE;
Foreach ($ array as $ key => $ value)
{
If ($ value! ==$ DeleteIt)
{
If (FALSE ===$ useOldKeys)
{
$ TmpArray [] = $ value;
}
Else
{
$ TmpArray [$ key] = $ value;
}
}
Else
{
$ Found = TRUE;
}
}

$ Array = $ tmpArray;

Return $ found;
}
?>


Bytes. The code is as follows...

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.