-
-
/** - * Function to remove duplicate values from array
- * by bbs.it-home.org
- */
- function array_assoc_unique($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 ];
- }
- }
- sort($arr);
- return $arr;
- }
//Call the example to remove duplicate values in the data
- $aa = array(
- array('id ' => 123, 'name' => 'Scripting School'),
- array('id' => 123, 'name' => 'php programming'),
- array('id' => 124, 'name' => 'Programmer's Home'),
- array('id' => 125, 'name' => 'Self-taught'),
- array('id' => 126, 'name' => 'Programmer's Home')
- );
- $key = 'name';
- array_assoc_unique(&$aa, $key);
- print_r($aa);
- ?>
-
Copy code
|