Php array processing array (4) {& nbsp; [0] = & gt; array (3) {& nbsp; [& quot; Id & quot;] = & gt; string (2) & quot; 24 & quot; & nbsp; [& quot; FromMid & quot;] = & gt; string (3) & quot; 1 php array processing
Array (4 ){
[0] => array (3 ){
["Id"] => string (2) "24"
["FromMid"] => string (3) "157"
["ToMid"] => string (3) "157"
}
[1] => array (3 ){
["Id"] => string (2) "22"
["FromMid"] => string (3) "157"
["ToMid"] => string (3) "176"
}
[2] => array (3 ){
["Id"] => string (1) "4"
["FromMid"] => string (3) "157"
["ToMid"] => string (2) "25"
}
[3] => array (3 ){
["Id"] => string (1) "1"
["FromMid"] => string (2) "25"
["ToMid"] => string (3) "157"
}
}
I want to remove only one ["FromMid"] = ["ToMid"] & ["ToMid"] = ["FromMid "]
The result should be
Array (4 ){
[0] => array (3 ){
["Id"] => string (2) "24"
["FromMid"] => string (3) "157"
["ToMid"] => string (3) "157"
}
[1] => array (3 ){
["Id"] => string (2) "22"
["FromMid"] => string (3) "157"
["ToMid"] => string (3) "176"
}
[2] => array (3 ){
["Id"] => string (1) "4"
["FromMid"] => string (3) "157"
["ToMid"] => string (2) "25"
}
}
------ Solution --------------------
PHP code
------ Solution --------------------
PHP code
$ Data = array ("Id" => "24", "FromMid" => "157", "ToMid" => "157 "), array ("Id" => "22", "FromMid" => "157", "ToMid" => "176 "), array ("Id" => "4", "FromMid" => "157", "ToMid" => "25 "), array ("Id" => "1", "FromMid" => "25", "ToMid" => "157"); $ markList = array (); foreach ($ data as $ key => $ val) {$ posi = md5 ($ val ['frommid']. $ val ['tomid ']); $ anti = md5 ($ val ['tomid']. $ val ['frommid']); if (isset ($ markList [$ posi]) | isset ($ markList [$ anti]) {unset ($ data [$ key]);} else {$ markList [$ posi] = $ markList [$ anti] = 1 ;}} echo''; Print_r ($ data);/** output: array ([0] => Array ([Id] => 24 [FromMid] => 157 [ToMid] => 157) [1] => Array ([Id] => 22 [FromMid] => 157 [ToMid] => 176) [2] = & gt; Array ([Id] = & gt; 4 [FromMid] = & gt; 157 [ToMid] = & gt; 25 )*/