我有这个数组:
precision
我的PHP代码:
Array
(
[0] => Array
(
[complet_title] => test1
[have_background] => 0
[condition_type] => 1
[state] => 1
)
[1] => Array
(
[complet_title] => test2
[have_background] => 1
[condition_type] => 1
[state] => 0
)
)
在foreach($a_sliders as $k => $slider){
switch($slider['condition_type']){
case 1:
if($slider['state'] == 1){
if(Test::check($id, $server)){
unset($a_sliders[$k]);
}else{
}
}
}
}
我要删除包含else
和condition_type = 1
的子数组。有可能做到这一点吗?你能帮我吗 ? Thx提前和抱歉我的英语
答案 0 :(得分:0)
array_filter($array, function($v){return ($v['condition_type'] != 1) || ($v['state'] != 0);})
答案 1 :(得分:0)
function remove($arr, $key1, $val1, $key2, $val2){
$foundKey = '';
foreach($arr as $k=>$a){
if($a[$key1] == $val1 && $a[$key2] == $val2){
$foundKey = $k;
}
}
if(isset($arr[$foundkey])){
unset($arr[$foundkey]);
}
return $arr;
}
现在调用删除功能:
remove($arr, 'state', '0', 'condition_type', '1');
答案 2 :(得分:0)
像这样使用,
foreach($a_sliders as $k => $slider){
switch($slider['condition_type']){
case 1:
if($slider['state'] == 1){
if(Test::check($id, $server)){
unset($a_sliders[$k]);
}
}
// your conditions are likely to be met here
else if ($slider['state'] == 0 && $slider['condition_type'] == 1){
unset($a_sliders[$k]);
}
}
}