PHP除开数组中指定的值

WBOY
Release: 2016-06-13 13:15:00
Original
1108 people have browsed it

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); ??

?

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template