1樓:匿名使用者
方案一$arr = array("0a","1b","2c","3d","4e","5f","6g","0a","2c","4e","6g","6g");
$arr1 = array_flip($arr);
$arr2 = array_flip($arr1);
print_r($arr2);
方案二$arr = array("0a","1b","2c","3d","4e","5f","6g","0a","2c","4e","6g","6g");
$a = array_count_values($arr);
$b = array_keys($a);
print_r($b);
方案三$arr = array("0a","1b","2c","3d","4e","5f","6g","0a","2c","4e","6g","6g");
foreach($arr as $k=>$v)
print_r($arr2);
方案四$arr = array("0a","1b","2c","3d","4e","5f","6g","0a","2c","4e","6g","6g");
$arr1 = array_unique($arr);
print_r($arr1);
都是剛剛我實驗出來的 都可以封裝起來用遞迴實現多維去掉重複項
2樓:匿名使用者
array_unique($array);
php如何去掉二維陣列中重複的元素?
3樓:匿名使用者
php陣列
抄去除重複項有個內建函式array_unique(),但是php的array_unique函式只適用於一維陣列,對多維陣列並不適用,不過你可以在二維陣列中的值,用array_unique()即可。
比如:$array = array(array(1,1,2),array(2,3,4,3));
$temp_array = array();
foreach($array as $key=>$value)$array = $temp_array;
4樓:匿名使用者
function remove_duplicate($array)
}return $result;
}$arr=array("1"=>array("a","b "),"2"=>array("a","c"),"3"=>array("a","b"));$arr=remove_duplicate($arr);print_r($arr);
5樓:怕孤單又已習慣
array_unique($arr,sort_regular)
php二維陣列如何去掉重複值
6樓:灰哥哥僒巈駥媎
php陣列去除重複項有個內建函式array_unique(),但是php的array_unique函式只適用於一維陣列,對多維陣列並不適用,以下提供一個二維陣列的array_unique函式。
function array_unique_fb($array2d)
$temp = array_unique($temp); //去掉重複的字串,也就是重複的一維陣列
foreach ($temp as $k => $v)return $temp;}
如果你想保留陣列的鍵值,可以用下面的函式:
//二維陣列去掉重複值 並保留鍵值
function array_unique_fb($array2d)$temp = array_unique($temp); //去掉重複的字串,也就是重複的一維陣列
foreach ($temp as $k => $v){$array=explode(",",$v); //再將拆開的陣列重新組裝
$temp2[$k]["id"] =$array[0];
$temp2[$k]["litpic"] =$array[1];
$temp2[$k]["title"] =$array[2];
$temp2[$k]["address"] =$array[3];
$temp2[$k]["starttime"] =$array[4];
$temp2[$k]["endtime"] =$array[5];
$temp2[$k]["classid"] =$array[6];
大概就這樣啦。
7樓:匿名使用者
方法一:
function array_unique_fb($array2d)$temp=array_unique($temp); //去掉重複的字串,也就是重複的一維陣列
foreach ($temp as $k => $v)return $temp;
}方法二:
//二維陣列去掉重複值,並保留鍵值
function array_unique_fb($array2d)$temp=array_unique($temp); //去掉重複的字串,也就是重複的一維陣列
foreach ($temp as $k => $v)return $temp2;}
php根據某一鍵值去除二維陣列中重複值
8樓:
簡單處理一下,只保留較新的登入時間。而且無重複。
<?php
$a=array(
array(
"role_id"=>"48357" ,
"login_time"=>"2011-08-14 00:02:26"
),array(
"role_id"=>"48357" ,
"login_time" => "2011-08-14 00:01:51"
),array(
"role_id"=> "48356",
"login_time"=> "2011-08-14 00:02:25"
),array(
"role_id"=> "48358",
"login_time"=> "2011-08-14 00:02:45"
),array(
"role_id"=> "48365",
"login_time"=> "2011-08-14 00:05:52"
),array(
"role_id"=> "48369" ,
"login_time"=> "2011-08-14 00:06:40"
),array(
"role_id"=> "48372",
"login_time"=> "2011-08-14 00:08:36"
),array(
"role_id"=> "48368",
"login_time"=> "2011-08-14 00:06:43"
),array(
"role_id"=> "48380" ,
"login_time"=> "2011-08-14 00:10:15"
),array(
"role_id"=> "48377" ,
"login_time"=> "2011-08-14 00:09:48"
),array(
"role_id"=> "48366" ,
"login_time"=> "2011-08-14 00:07:08"));
$b=array();
foreach($a as $e)
$b=array_values($b);
var_dump($b);
**********===
顯示array
0 =>
array
'role_id' => string '48357' (length=5)
'login_time' => string '2011-08-14 00:02:26' (length=19)
1 =>
array
'role_id' => string '48356' (length=5)
'login_time' => string '2011-08-14 00:02:25' (length=19)
2 =>
array
'role_id' => string '48358' (length=5)
'login_time' => string '2011-08-14 00:02:45' (length=19)
3 =>
array
'role_id' => string '48365' (length=5)
'login_time' => string '2011-08-14 00:05:52' (length=19)
4 =>
array
'role_id' => string '48369' (length=5)
'login_time' => string '2011-08-14 00:06:40' (length=19)
5 =>
array
'role_id' => string '48372' (length=5)
'login_time' => string '2011-08-14 00:08:36' (length=19)
6 =>
array
'role_id' => string '48368' (length=5)
'login_time' => string '2011-08-14 00:06:43' (length=19)
7 =>
array
'role_id' => string '48380' (length=5)
'login_time' => string '2011-08-14 00:10:15' (length=19)
8 =>
array
'role_id' => string '48377' (length=5)
'login_time' => string '2011-08-14 00:09:48' (length=19)
9 =>
array
'role_id' => string '48366' (length=5)
'login_time' => string '2011-08-14 00:07:08' (length=19)
9樓:笑一路
不知道這個陣列裡元素多不多。如果不考慮效能的話,需要迴圈。
另外建個陣列,存唯一的role_id。
10樓:匿名使用者
效能肯定高不了.就算是php內建的函式,處理方法也都差不多.
如果是資料庫呢.可能稍微好一點.
在php中,有個多維陣列b array有個字串
b array 定義二維陣列 0 array 1,2,3 1 array 4,5,6 2 array 7,8,9 a 2 1 定義字串 a m str replace a 把 x y 換成x y m str replace m 把 x y 換成x y m str replace m 把 x y 換成...
php怎麼使二維陣列變一維陣列同時去掉相同元素
php陣列去除重複du項有個內建函式array unique 但是zhiphp的array unique函式只適用dao於一維陣列,對多維專陣列並不適用,不過你可以在二維陣列中屬的值,用array unique 即可。比如 array array array 1,1,2 array 2,3,4,3 ...
php二維陣列合成2維陣列,條件是lid id的合併
按照你的要求合併兩個二維陣列的php程式如下 arr1 array array lid 67,title t恤 array lid 27,title 襯衣 arr1 array array lid 67,title t恤 array lid 27,title 襯衣...