u012575301 于 2014.12.06 21:01 提问

Array
(
[0] => Array
(
[year] => 2013-2014
[term] => 1
[course_code] => 00008069
[course_name] => 咖啡世界
[course_nature] => 任意选修
[credit] => 2.0
[point] => 4.1
[minor_tag] => 0

[begin_college] => 旅游文化产业学院
[remark] =>

[rebuild_tag] => 0
[0] => 77
[1] => 2
)

``````                    [1] => Array
(
[year] => 2013-2014
[term] => 1
[course_code] => 00008069
[course_name] => 咖啡世界
[course_nature] => 任意选修
[credit] => 2.0
[point] => 4.1
[minor_tag] => 0
[begin_college] => 旅游文化产业学院
[remark] => &nbsp;
[rebuild_tag] => 0
[0] => 77
[1] => 2
)

[2] => Array
(
[year] => 2013-2014
[term] => 1
[course_code] => 00008069
[course_name] => 咖啡世界
[course_nature] => 任意选修
[credit] => 2.0
[point] => 4.1
[minor_tag] => 0
[begin_college] => 旅游文化产业学院
[remark] => &nbsp;
[rebuild_tag] => 0
[0] => 77
[1] => 2
)
``````

)

Array
(
[0] => Array
(
[year] => 2013-2014
[term] => 1
[course_code] => 00008069
[course_name] => 咖啡世界
[course_nature] => 任意选修
[credit] => 2.0
[point] => 4.1
[minor_tag] => 0

[begin_college] => 旅游文化产业学院
[remark] =>

[rebuild_tag] => 0
[0] => 77
[1] => 2
)
}

2个回答

piaoxue0145   2014.12.08 11:34

01
//二维数组去掉重复值
02
function array_unique_fb(\$array2D)
03
{
04
foreach (\$array2D as \$v)
05
{
06
\$v = join(",",\$v); //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
07
\$temp[] = \$v;
08
}
09

10
\$temp = array_unique(\$temp); //去掉重复的字符串,也就是重复的一维数组
11
foreach (\$temp as \$k => \$v)
12
{
13
\$temp[\$k] = explode(",",\$v); //再将拆开的数组重新组装
14
}
15
return \$temp;
16
}

01
//二维数组去掉重复值 并保留键值
02
function array_unique_fb(\$array2D)
03
{
04
foreach (\$array2D as \$k=>\$v)
05
{
06
\$v = join(",",\$v); //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
07
\$temp[\$k] = \$v;
08
}
09
\$temp = array_unique(\$temp); //去掉重复的字符串,也就是重复的一维数组
10
foreach (\$temp as \$k => \$v)
11
{
12
\$array=explode(",",\$v); //再将拆开的数组重新组装
13
\$temp2[\$k]["id"] =\$array[0];

14
\$temp2[\$k]["litpic"] =\$array[1];
15
\$temp2[\$k]["title"] =\$array[2];
16
17
\$temp2[\$k]["starttime"] =\$array[4];
18
\$temp2[\$k]["endtime"] =\$array[5];
19
\$temp2[\$k]["classid"] =\$array[6];
20
\$temp2[\$k]["ename"] =\$array[7];
21
}
22
return \$temp2;
23
}

asasaas121   2014.12.09 17:31
`````` \$arr=array(
0=>array(
'name'=>"xxx",
'age'=>23,
'school'=>"yyyy大学"
),
1=>array(
'name'=>"xxx",
'age'=>23,
'school'=>"yyyy大学"
),
2=>array(
'name'=>"xxx",
'age'=>23,
'school'=>"yyyy大学"
)
);
\$delete_key=0;//需要找的重复的数组的下标值
\$value=\$arr[\$delete_key];//获取其值
\$key=array_keys(\$arr,\$value);//需要同样的值的下标
foreach (\$key as \$k=>\$v)
{
if(\$v!=\$delete_key)//第一个值不删，其它的删除
unset(\$arr[\$v]);
}
echo"<pre>";
var_dump(\$arr);
echo"</pre>";
``````