Heim >Backend-Entwicklung >PHP-Tutorial >php数组过滤有关问题
php数组过滤问题
假设数组
array(0 => array('catid' => 10 , 'parent' => '1') , 1 => array('catid' => 11 , 'parent' => 1) , array('catid' => 21 , 'parent' => 2) );
我希望只保留 parent 为2的值要怎么做呢?
小弟新人希望大侠帮忙 谢谢!
$a = array(0 => array('catid' => 10 , 'parent' => '1') , 1 => array('catid' => 11 , 'parent' => 1) , array('catid' => 21 , 'parent' => 2) );<br />$t = array_map(function($v) { return array('parent' => $v['parent']); }, $a);<br />/*<br />php 5.2.x 写作<br />$t = array_map(create_function('$v', 'return array("parent" => $v["parent"]);'), $a);<br />*/<br />print_r($t);Array