我想從數組中刪除鍵。如何從數組中刪除特定的鍵? PHP
這是我從印刷print_r($貓)得到的;
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' – 2011-03-05 06:24:28
@tandu:謝謝。更新。 – Gaurav 2011-03-05 06:26:33
if(strpos($ value,$ toDelete)!== false)我也得到解析器錯誤 – user585303 2011-03-05 06:29:30