Home > Backend Development > PHP Tutorial > How to implement php unset to delete array variables_PHP tutorial

How to implement php unset to delete array variables_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-20 11:02:01
Original
1161 people have browsed it

To delete data and variables, you can use unset in PHP. Of course, you can also use empty processing, but destroy the variables and let the PHP variables disappear in the memory. ​

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

$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 deleting keys in an array. Be aware that the array will not be reindexed.
$a = array( 1 => 'one', 2 => 'two', 3 => 'three' );
unset( $a[2] );
/* will generate an array, defined as
$a = array( 1=>'one', 3=>'three');
instead of
$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() will return true (actually the integer value 1),
In PHP 4, unset() is no longer a real function: it is now a statement


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445400.htmlTechArticleTo delete data and variables, you can use unset in php. Of course, you can also use empty space. Process, but destroy the variables and let the php variables disappear in the memory. To delete data...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template