Home >Backend Development >PHP Tutorial > 求解一题!该怎么解决

求解一题!该怎么解决

WBOY
WBOYOriginal
2016-06-13 12:49:49822browse

求解一题!
$arr=array(
   array('id'=>1,'title'=>'分类1'),
   array('id'=>3,'title'=>'分类3'),
   array('id'=>2,'title'=>'分类2'),
   array('id'=>8,'title'=>'分类8'),
   array('id'=>111,'title'=>'分类111'),
);

删除上述 数组中  id=2 的数组 (也就是array('id'=>2,'title'=>'分类2'))


------解决方案--------------------
$arr=array(<br />
   array('id'=>1,'title'=>'分类1'),<br />
   array('id'=>3,'title'=>'分类3'),<br />
   array('id'=>2,'title'=>'分类2'),<br />
   array('id'=>8,'title'=>'分类8'),<br />
   array('id'=>111,'title'=>'分类111'),<br />
);<br />
foreach($arr as $k=>$v) if($v['id'] == 2) unset($arr[$k]);<br />
print_r($arr);<br />
Array
(
    [0] => Array
        (
            [id] => 1
            [title] => 分类1
        )

    [1] => Array
        (
            [id] => 3
            [title] => 分类3
        )

    [3] => Array
        (
            [id] => 8
            [title] => 分类8
        )

    [4] => Array
        (
            [id] => 111
            [title] => 分类111
        )

)
Statement:
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