【发布时间】:2011-07-09 07:02:35
【问题描述】:
我正在尝试从数组中删除键。
这是我通过打印 print_r($cats); 得到的结果
Array
(
[0] => <a href="/website/index.php/Category:All" title="Category:All">All</a> > <a href="/website/index.php/Category:Computer_errors" title="Category:Computer errors">Computer errors</a> > <a href="/website/index.php/Category:HTTP_status_codes" title="Category:HTTP status codes">HTTP status codes</a> > <a href="/website/index.php/Category:Internet_terminology" title="Category:Internet terminology">Internet terminology</a>
[1] =>
<a href="/website/index.php/Category:Main" title="Category:Main">Main</a>
)
我正在尝试使用它从数组中删除“主要”类别
function array_cleanup( $array, $todelete )
{
foreach( $array as $key )
{
if ( in_array( $key[ 'Main' ], $todelete ) )
unset( $array[ $key ] );
}
return $array;
}
$newarray = array_cleanup( $cats, array('Main') );
仅供参考,我是 PHP 新手...显然我看到我犯了错误,但我已经尝试了很多东西,但它们似乎不起作用
【问题讨论】: