array_unique for arrays inside array

前端 未结 3 1214
忘了有多久
忘了有多久 2021-01-17 09:13

I need a function like array_unique for arrays inside array.

The Case - should be equal, but output \"not equal\":



        
相关标签:
3条回答
  • 2021-01-17 09:31

    If you want to test if the outer array has unique entries, then stringify the inner contents first for a comparison:

    $arr1 = array_map("serialize", $arr);
    $arr2 = array_unique($arr1);
    if ($arr2 == $arr1) {
    
    0 讨论(0)
  • 2021-01-17 09:32

    You should modify your call for array_unique to have it include the SORT_REGULAR flag.

    $arr2 = array_unique($arr, SORT_REGULAR);
    
    0 讨论(0)
  • 2021-01-17 09:34
    function array_unique_when_values_are_serializable($main_array) {
        return array_map('unserialize', array_values(array_unique(array_map('serialize', $main_array))));
    }
    
    0 讨论(0)
提交回复
热议问题