Two efficient and classic methods for deleting array elements are provided below. We can delete the ones that we want to delete. Students in need can refer to them. Here are the methods from php.net.
The code is as follows |
Copy code |
代码如下 |
复制代码 |
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;
}
?>
|
The code is as follows |
Copy code |
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;
}
?>
|
http://www.bkjia.com/PHPjc/445321.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445321.htmlTechArticle
The following are two efficient and classic methods for deleting array elements. We can delete the one we want to delete if necessary. Students can refer to it, here is from php.net. The code is as follows...
|