Home > Backend Development > PHP Tutorial > PHP deletes a value in an array. Compatible with multi-dimensional arrays!_PHP Tutorial

PHP deletes a value in an array. Compatible with multi-dimensional arrays!_PHP Tutorial

WBOY
Release: 2016-07-21 15:21:13
Original
1151 people have browsed it

复制代码 代码如下:

function array_remove_key($array, $keys)
{
$num = count($keys);
$num_last = $num - 1;
$this_array_0 = &$array;
$last_key = $keys[$num_last];
for ($i = 0; $i < $num_last; $i++)
{
$this_key = $keys[$i];
$this_var_name = 'this_array_' . $i;
$next_var_name = 'this_array_' . ($i + 1);
if (!array_key_exists($this_key, $$this_var_name)) {
break;
}
$$next_var_name = &${$this_var_name}[$this_key];
}
unset(${$next_var_name}[$last_key]);
return $array;
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/324957.htmlTechArticle复制代码 代码如下: function array_remove_key($array, $keys) { $num = count($keys); $num_last = $num - 1; $this_array_0 = $last_key = $keys[$num_last]; for ($i = 0; $i $num_...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template