我正在尝试从数组中删除键。
这是我从打印 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不熟悉......很明显,我犯了错误,但我已经尝试了很多方法,它们似乎都不起作用。
strpos($value, $toDelete) !== false
。 - Explosion Pillsstr_replace()
。http://www.php.net/manual/zh/function.str-replace.php - Gaurav!== false
,而不是! == false
。 - Explosion Pills