Home > Backend Development > PHP Tutorial > 怎么删除多维数组中的一组数组

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

WBOY
Release: 2016-06-13 11:58:02
Original
1280 people have browsed it

如何删除多维数组中的一组数组

<?php<br />'Ftps' => <br />  array (<br />    0 => <br />    array (<br />      'id' => '1',<br />      'uid' => '1',<br />      'order_id' => '0',<br />      'sid' => '2',<br />      'name' => 'admin123',<br />      'master' => '0'<br />    ),<br />    1 => <br />    array (<br />      'id' => '2',<br />      'uid' => '2',<br />      'order_id' => '0',<br />      'sid' => '2',<br />      'name' => 'admin350',<br />      'master' => '1'<br />    ),<br />    2 => <br />    array (<br />      'id' => '3',<br />      'uid' => '3',<br />      'order_id' => '0',<br />      'sid' => '2',<br />      'name' => 'admin150',<br />      'master' => '0'<br />    ),<br />  )<br />);<br /><br />//我想,把 'master' => '1' 这一组数组删除 ,循环出来后<br />foreach($Ftps AS $key=>$rs){<br />	<br />}<br />//////////////////////////////////////////////////////////////////////////////<br />'Ftps' => <br />  array (<br />    0 => <br />    array (<br />      'id' => '1',<br />      'uid' => '1',<br />      'order_id' => '0',<br />      'sid' => '2',<br />      'name' => 'admin123',<br />      'master' => '0'<br />    ),<br />    1 => <br />    array (<br />      'id' => '3',<br />      'uid' => '3',<br />      'order_id' => '0',<br />      'sid' => '2',<br />      'name' => 'admin150',<br />      'master' => '0'<br />    ),<br />  )<br />);<br />?>
Copy after login

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

array (<br>  'Ftps' => <br>  array (<br>    0 => <br>    array (<br>      'id' => '1',<br>      'uid' => '1',<br>      'order_id' => '0',<br>      'sid' => '2',<br>      'name' => 'admin123',<br>      'master' => '0',<br>    ),<br>    1 => <br>    array (<br>      'id' => '3',<div class="clear">
                 
              
              
        
            </div>
Copy after login
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