3

I have address array. I want to get unique address records from below array. I have used lots of logic but all fails to extract unique address. If we get any differences between keys like address_one, address_two etc. with another one, then I will consider as unique, but here some array values same with others.

Array
(    
0 => Array
        (
            'address_one' => 'qqqqqqqqqq',
            'address_two' => 'wwwwww',
            'zipcode' => '212121',
            'country_id' => '1',
            'country_name' => 'United States',
            'state_id' => '5',
            'state_name' => 'AP',
            'city_id' => '3',
            'city_name' => 'Bhopal'
        ),    
1 => Array
        (
            'address_one' => 'lkl',
            'address_two' => 'ik2',
            'zipcode' => '564564',
            'country_id' => '1',
            'country_name' => 'United States',
            'state_id' => '1',
            'state_name' => 'Madhya Pradesh',
            'city_id' => '1',
            'city_name' => 'Indore'
        ),    
2 => Array
        (
            'address_one' => 'ace1',
            'address_two' => 'caldrys1',
            'zipcode' => '564561',
            'country_id' => '91',
            'country_name' => 'Guinea',
            'state_id' => '3',
            'state_name' => 'AL',
            'city_id' => '3',
            'city_name' => 'Bhopal'
        ),    
3 => Array
        (
            'address_one' => '',
            'address_two' => '',
            'zipcode' => '',
            'country_id' => '',
            'country_name' => '',
            'state_id' => '',
            'state_name' => '',
            'city_id' => '',
            'city_name' => ''
        ),    
4 => Array
        (
            'address_one' => '',
            'address_two' => '',
            'zipcode' => '',
            'country_id' => '',
            'country_name' => '',
            'state_id' => '',
            'state_name' => '',
            'city_id' => '',
            'city_name' => ''
        ),    
5 => Array
        (
            'address_one' => 'lkl',
            'address_two' => 'ik2',
            'zipcode' => '564564',
            'country_id' => '1',
            'country_name' => 'United States',
            'state_id' => '1',
            'state_name' => 'Madhya Pradesh',
            'city_id' => '1',
            'city_name' => 'Indore'
        ),    
6 => Array
        (
            'address_one' => 'Ace',
            'address_two' => 'Matru Line',
            'zipcode' => '483504',
            'country_id' => '100',
            'country_name' => 'India',
            'state_id' => '1',
            'state_name' => 'Madhya Pradesh',
            'city_id' => '2',
            'city_name' => 'Katni'
        ),    
7 => Array
        (
            'address_one' => 'lkl',
            'address_two' => 'ik2',
            'zipcode' => '564564',
            'country_id' => '1',
            'country_name' => 'United States',
            'state_id' => '1',
            'state_name' => 'Madhya Pradesh',
            'city_id' => '1',
            'city_name' => 'Indore'
        ),
8 => Array
        (
            'address_one' => 'ace1',
            'address_two' => 'caldrys1',
            'zipcode' => '564561',
            'country_id' => '91',
            'country_name' => 'Guinea',
            'state_id' => '3',
            'state_name' => 'AL',
            'city_id' => '3',
            'city_name' => 'Bhopal'
        )

);
5
  • 3
    1) Have you tried something? Show your attempts! 2) What is the current output and what do you expect to get? Commented Aug 3, 2015 at 15:04
  • 1
    @Rizier123: 4 upvotes for this question and 4 upvotes for the answer. What on earth is going on? ;=D Commented Aug 3, 2015 at 15:44
  • @halfer earth is broken with many fatal syntax errors in it :} Like this question. Commented Aug 3, 2015 at 15:45
  • I have used lots of complex method, using loop and keeping values another array but all of things not working properly. Also used In_array, array_intersect, array_diff etc. Commented Aug 3, 2015 at 16:00
  • Would you give us an example of all of the things that did not work properly, edited into your question? Many thanks. Commented Aug 4, 2015 at 0:54

2 Answers 2

5

To get unique multidimensional array you can use this :

$output_array = array_map(
    "unserialize",
    array_unique(array_map("serialize", $input_array))
);
Sign up to request clarification or add additional context in comments.

1 Comment

Given how difficult the original post was to understand, I am impressed you got it in 17 minutes without any clarifications required. You've managed to get additional congratulatory messages as well, and four quick upvotes - good work! However, please be aware that if any of you know each other, there is no value in answering each other's questions - voting ring detection is very good on Stack Overflow, and is soon reversed.
1

Please use this to get unique array.

$output_array = array_unique($input_array, SORT_REGULAR);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.