本文实例讲述了PHP删除二维数组中相同元素及数组重复值的方法。分享给大家供大家参考,具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
function assoc_title( $arr , $key ) { $tmp_arr = array (); foreach ( $arr as $k => $v ) { if (in_array( $v [ $key ], $tmp_arr )) { unset( $arr [ $k ]); } else { $tmp_arr [] = $v [ $key ]; } } return $arr ; } //assoc_title end $key_title = 'stu_name' ; $quchong = assoc_title( $teachers , $key_title ); echo "<table border=\"1\" bordercolor=\"#CCCCCC\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse:collapse\" width=\"20%\">" ; echo "<tr><td>id</td><td>学生名</td><td>电话</td></tr>" ; $i = 1; foreach ( $quchong as $key => $vale ) { if ( $vale [ 'stu_name' ] == "游开琳" or $vale [ 'stu_name' ] == "韩建通" ) { continue ; } echo "<tr><td>{$i}</td><td>{$vale['stu_name']}</td><td>{$vale['tel']}</td></tr>" ; $i ++; } echo "</table>" ; |
希望本文所述对大家PHP程序设计有所帮助。