当前位置:Gxlcms > PHP教程 > 怎么删除多维数组中的一组数组

怎么删除多维数组中的一组数组

时间:2021-07-01 10:21:17 帮助过:5人阅读

如何删除多维数组中的一组数组
'Ftps' => 
array (
0 =>
array (
'id' => '1',
'uid' => '1',
'order_id' => '0',
'sid' => '2',
'name' => 'admin123',
'master' => '0'
),
1 =>
array (
'id' => '2',
'uid' => '2',
'order_id' => '0',
'sid' => '2',
'name' => 'admin350',
'master' => '1'
),
2 =>
array (
'id' => '3',
'uid' => '3',
'order_id' => '0',
'sid' => '2',
'name' => 'admin150',
'master' => '0'
),
)
);

//我想,把 'master' => '1' 这一组数组删除 ,循环出来后
foreach($Ftps AS $key=>$rs){

}
//////////////////////////////////////////////////////////////////////////////
'Ftps' =>
array (
0 =>
array (
'id' => '1',
'uid' => '1',
'order_id' => '0',
'sid' => '2',
'name' => 'admin123',
'master' => '0'
),
1 =>
array (
'id' => '3',
'uid' => '3',
'order_id' => '0',
'sid' => '2',
'name' => 'admin150',
'master' => '0'
),
)
);
?>

------解决方案--------------------
引用:
$ar = array(
'Ftps' =>
array (
0 =>
array (
'id' => '1',
'uid' => '1',
'order_id' => '0',
'sid' => '2',
'name' => 'admin123',
'master' => '0'
),
1 =>
array (
'id' => '2',
'uid' => '2',
'order_id' => '0',
'sid' => '2',
'name' => 'admin350',
'master' => '1'
),
2 =>
array (
'id' => '3',
'uid' => '3',
'order_id' => '0',
'sid' => '2',
'name' => 'admin150',
'master' => '0'
),
)
);
$ar['Ftps'] = array_values(array_filter($ar['Ftps'], function($t) { return $t['master'] != '1'; }));
var_export($ar);
array (
'Ftps' =>
array (
0 =>
array (
'id' => '1',
'uid' => '1',
'order_id' => '0',
'sid' => '2',
'name' => 'admin123',
'master' => '0',
),
1 =>
array (
'id' => '3',

人气教程排行