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

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

WBOY
WBOYOriginal
2016-06-13 11:58:021284browse

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

<?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 />?>

------解决方案--------------------

引用:
$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);
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>
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