PHPで二次元配列からフィールドを削除するにはどうすればよいですか?
1. 要件: 次の 2 次元配列があります。この配列のフィールド "on" を削除して新しい配列を生成する方法 $arr2
$arr = array("net" => array( "on", "11 ", "101", "1001"),
"login" => array("on", "10001","100001","1000001"));
$arr2 = array ("net" =>array( "11", "101", "1001"),
"login" => array("10001", "100001", "1000001") ));
または、
2 を通過するときに on を削除すると、この効果を達成することもできます
$arr = array("net" => array("on","1", "2 ","4" ),
"login" => array("on","10001","100001","10000001")
);
$str ='';
foreach ($arr as $key=>$value){
foreach ($value as $k =>$v){
$str=$str|$v;
}
}
var_dump($str);
//値演算後の数値の OR 演算の結果、値 $str が得られます。「on」フィールドは演算に参加できません
-- ----解決策のアイデア---------------------
1.
$arr = array(<br /> "net" => array("on", "11", "101", "1001"),<br /> "login" => array("on", "10001","100001","1000001")<br />);<br /><br />array_walk($arr, function(&$t) {<br /> $t = array_diff($t, array('on'));<br />});<br /><br />print_r($arr);
Array<br />(<br /> [net] => Array<br /> (<br /> [1] => 11<br /> [2] => 101<br /> [3] => 1001<br /> )<br /><br /> [login] => Array<br /> (<br /> [1] => 10001<br /> [2] => 100001<br /> [3] => 1000001<br /> )<br /><br />)<br />
$arr = array(<br /> "net" => array("on", "11", "101", "1001"),<br /> "login" => array("on", "10001","100001","1000001")<br />);<br /><br />$str ='';<br />foreach ($arr as $key=>$value){<br /> foreach ($value as $k =>$v){<br /> if($v != 'on') $str = $str<br><font color='#FF8000'>------解决思路----------------------</font><br>$v;<br /> }<br />}<br />var_dump($str);
string(7) "1111111"<br />
<br />$arr = array("net" => array("on", "11", "101", "1001"),<br /> "login" => array("on", "10001","100001","1000001"));<br /><br />delon($arr);<br />print_r($arr);<br /><br /><br />function delon(&$arr){<br /> foreach($arr as $key=>&$val){<br /> foreach($val as $k=>$v){<br /> if($v=='on'){<br /> unset($val[$k]);<br /> }<br /> }<br /> }<br />}<br />