function unique_array_2d ($array, $stkeep =false, $ndformat =true) { Determines whether to preserve the first-level array key (the first-level array key can be non-numeric) if ($stkeep) $STARR = Array_keys ($array 2D);
Determines whether to preserve level two array keys (all two-level array keys must be the same) if ($ndformat) $NDARR = Array_keys (end ($array 2D)); Dimension, you can also convert one-dimensional array to a comma-concatenated string using implode foreach ($array 2D as $v) { $v = Join (",", $v); $temp [] = $v; } Remove duplicate strings, that is, duplicate one-dimensional arrays $temp = Array_unique ($temp); Re-assemble the disassembled array foreach ($temp as $k = $v) { if ($stkeep) $k = $STARR [$k]; if ($ndformat) { $TEMPARR = Explode (",", $v); foreach ($tempArr as $ndkey = $ndval) $output [$k] [$NDARR [$ndkey]] = $ndval; } else $output [$k] = Explode (",", $v); } return $output; } $array 2D = Array ( ' First ' =>array (' title ' = ' 1111 ', ' date ' = ' 2222 '), ' Second ' =>array (' title ' = ' 1111 ', ' date ' = ' 2222 '), ' Third ' =>array (' title ' = ' 2222 ', ' date ' = ' 3333 ') ); echo " "; Print_r (unique_array_2d ($array 2d,true));/** * Resets the two-dimensional array by the specified key to * * @param array $arr to go to the heavy arrays * @param array $by Specify key to go to weight, the parameter does not specify that the array () * is returned @re Turn array */ Function Array_multunique ($arr, $by = Array ()) { $temp = array (); foreach ($arr as $key = + $val) { foreach ($by as $v) { $temp [$key]. = Isset ($ val[$v])? $val [$v]: '; } } return Array_intersect_key ($arr, Array_unique ($temp)); } /* $aa = Array ( Array (' id ' = = 123, ' name ' = ' Zhang San '), Array (' id ' = = 123, ' name ' = ' John Doe ') ), Array (' id ' = = 124, ' name ' = = ' Harry '), Array (' id ' = = ', ' name ' = ' Zhao Liu '), Arra Y (' id ' = = 126, ' name ' = ' Zhao Liu ') ); $key = ' id '; Array_multunique ($AA, array (' ID ')); */ function Array_remove_key ($array, $keys) { if (!is_array ($array) | |!is_array ($keys)) { return false; } foreach ($array as $t) { foreach ($keys as $k) { Unset ($t [$k]); } $doc []= $t; } return $doc; } /* $array = Array ( ' 0 ' = = Array (' a ' = = ' aaaaa ', ' b ' = = ' bbbbb ', ' c ' = = ' Array (' d ' + = ' ddddd ', ' e ' = ' eeeee ') '), ' 1 ' = = Array (' a ' = ' = ' aaaaa ', ' b ' = ' = ' bbbbb ', ' c ' = = = Array (' d ' = = ' ddddd ', ' e ' = ' eeeee ')) ); Print_r (Array_remove_key ($array, Array (' C '))); */ Function Array_remove_key_val (& $a, $b, $c) { foreach ($a as $key = = $value) { if (Isset ($value [$b]) && ($value [$b]== $c)) { unset ($a [$key]); } } } /* $a =array ( Array (' ID ' =>1, ' num ' =>10, ' type ' = ' news '), Array (' ID ' =>2, ' num ' =>100, ' type ' = ' pic ') ); Print_r (Array_remove_key_val ($a, "id", "1")); */ |