Php removes the repeated items of two-dimensional arrays, and php removes two-dimensional arrays. Php removes duplicate items from two-dimensional arrays. php removes duplicate items from two-dimensional arrays in php. you can use the php built-in function array_unique (), however, the array_unique function of php removes the repeated items of the two-dimensional array from the multi-dimensional php, and php removes the two-dimensional array.
The php built-in function array_unique () can be used to remove repeated items from one-dimensional arrays. However, the php array_unique function is not applicable to multi-dimensional arrays. how can we remove repeated items from two-dimensional arrays?
The following is a function.
// Remove the duplicate value from the two-dimensional array function unique_arr ($ array2D, $ stkeep = false, $ ndformat = true) {$ joinstr = '++ '; // Determine whether the primary array key is retained (the primary array key can be non-numeric) if ($ stkeep) $ stArr = array_keys ($ array2D ); // Determine whether the secondary array key is retained (all secondary array keys must be the same) if ($ ndformat) $ ndArr = array_keys (end ($ array2D); // dimension reduction, you can also use implode to convert a one-dimensional array to a comma-connected string foreach ($ array2D as $ v) {$ v = join ($ joinstr, $ v ); $ temp [] = $ v;} // remove the duplicate string, that is, the repeated one-dimensional array $ temp = array_unique ($ temp ); // re-assemble the split array foreach ($ temp as $ k => $ v) {if ($ stkeep) $ k = $ stArr [$ k]; if ($ ndformat) {$ tempArr = explode ($ joinstr, $ v); foreach ($ tempArr as $ ndkey => $ ndval) $ output [$ k] [$ ndArr [$ ndkey] = $ ndval;} else $ output [$ k] = explode ($ joinstr, $ v );} return $ output ;}
I hope it will be helpful for you to learn about php programming.
Repeated items for removing one-dimensional arrays in php can be implemented using the php built-in function array_unique (), but the php array_unique function is used for multi-dimensional data...