Php unset Implementation of deleting array Variables

Source: Internet
Author: User

To delete data and variables, you can use the unset function in php. Of course, you can also use the null function to process them. However, you can destroy the variable so that the php variable disappears in the memory.

To delete data and variables, you can use the unset function in the php tutorial. Of course, you can also use the null function. However, destroy the variable so that the php variable disappears in the memory.
*/

$ Array = array ('A' => 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, 'A '));

/*
Unset ();
This function allows you to cancel the key name in an array. Note that the array will not rebuild the index.
$ A = array (1 => 'one', 2 => 'two', 3 => 'three ');
Unset ($ a [2]);
/* Generates an array, defined
$ A = array (1 => 'one', 3 => 'three ');
Instead
$ A = array (1 => 'one', 2 => 'three ');
Clear the entire array
Unset ($ arr );
4: Clear the specified Element
Unset ($ arr [index]);
Unset () destroys the specified variable. Note that 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


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.