Home  >  Article  >  Backend Development  >  PHP除开数组中指定的值

PHP除开数组中指定的值

WBOY
WBOYOriginal
2016-06-13 13:15:001106browse

PHP去除数组中指定的值

?

//一维数组

?

简单的做法 ?unset($arr[array_search($value,$arr)])

?

?

$arr = array("a","b","c","d"); ?

function isHave($var){ ?

? if($var!="b") ?

? return true; ?

} ?

$arr_filter = array_values(array_filter($arr,"isHave")); ?

//print_r($arr_filter); ?

?

while ( $folder = current ( $folders ) ) { ?

? ? if ($folder == $cur_folder) { ?

? ? ? ? $kv = key ( $folders ); ?

? ? ? ? unset ( $folders [$kv] ); ?

? ? } ?

? ? next ( $folders ); ?

} ? ? ? ??

?

//二维数组 ?

function killarray(&$a,$b,$c){ ?

? ? foreach ($a as $key=>$value){ ?

? ? ? ? if ( isset($value[$b]) && ($value[$b]==$c) ){ ?

? ? ? ? ? ? unset($a[$key]); ?

? ? ? ? } ?

? ? } ?

} ?

$a=array(array('id'=>1,'num'=>10,'type'=>'news'),array('id'=>2,'num'=>100,'type'=>'pic')); ?

$b="id"; ?

$c="1"; ?

killarray($a,$b,$c); ?

print_r($a); ??

?

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