PHP unset Delete Array variable implementation method _php tutorial

Source: Internet
Author: User
To delete data and variables in PHP using the work of the unset can be implemented, of course, you can also use the empty also processing, but destroy variables, let PHP variables in memory disappear OH.

To delete the data and variables in PHP tutorial use the work of the unset can be implemented, of course, you can also use the empty also processing, but destroy variables, let PHP variables in memory disappear OH.
*/

$array = Array (' AA ' =>1, ' BB ' =>2);

function Delete (& $array, $key)
{
if (!is_array ($key)) {
$key = Array ($key);
}
foreach ($key as $k) {
Unset ($array [$k]);
}
$array = Array_values ($array);
}


Print_r (Array_values ($array));

Print_r (Delete ($array, ' AA '));

/*
Unset ();
This function allows you to cancel the key names in an array. Be aware that the array will not rebuild the index.
$a = Array (1 = ' one ', 2 = ' both ', 3 = ' three ');
Unset ($a [2]);
/* will produce an array, defined as
$a = array (1=> ' one ', 3=> ' three ');
Instead of
$a = Array (1 = ' one ', 2 = ' three ');
Empty the entire array
Unset ($arr);
4: Empty the specified element
unset ($arr [index]);
Unset () destroys the specified variable. Note in PHP 3, unset () returns True (actually an integer value of 1).
In PHP 4, unset () is no longer a real function: it is now a statement


http://www.bkjia.com/PHPjc/445400.html www.bkjia.com true http://www.bkjia.com/PHPjc/445400.html techarticle to delete data and variables in PHP using the work of the unset can be implemented, of course, you can also use the empty also processing, but destroy variables, let PHP variables in memory disappear OH. To delete data ...

  • Related Article

    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.