Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have an issue to remove duplicates entries from three different array. Let me create the structure of an array.

 array (
'table_id' => 
array (
  1 => '1',
  2 => '1',
  3 => '1',
  4 => '1', 
  5 => '1',
  6 => '1',
  7 => '1',
  8 => '1', <-- This entry have value '1' : 
  14 => '1',
  17 => '1',
  20 => '1', <-- This entry have value '1' : 
  21 => '1',
  25 => '1',
  28 => '1', <-- This entry have value '1' : 
),
'no_of_seats' => 
array (
  1 => '2',
  2 => '2',
  3 => '2',
  4 => '2',
  5 => '2',
  6 => '4',
  7 => '4',
  8 => '4', <-- This entry have value '4' : 
  14 => '8',
  17 => '2',
  20 => '4', <-- This entry have value '4' : 
  21 => '8',
  25 => '6',
  28 => '4', <-- This entry have value '4' : 
),
'dt_time_slot' => 
array (
  1 => '4:30',
  2 => '6:30',
  3 => '9:00',
  4 => '17:00',
  5 => '23:00',
  6 => '0:30',
  7 => '1:30',
  8 => '4:30', <-- This entry have value '4:30' : 
  14 => '4:00',
  17 => '19:00',
  20 => '4:30', <-- This entry have value '4:30' : 
  21 => '6:30',
  25 => '7:30',
  28 => '4:30', <-- This entry have value '4:30' : 
));

the resulted array should be:

 array (
'table_id' => 
array (
  1 => '1',
  2 => '1',
  3 => '1',
  4 => '1', 
  5 => '1',
  6 => '1',
  7 => '1',
  8 => '1', <-- This entry have value '1' : 
  14 => '1',
  17 => '1',
  21 => '1',
  25 => '1',
),
'no_of_seats' => 
array (
  1 => '2',
  2 => '2',
  3 => '2',
  4 => '2',
  5 => '2',
  6 => '4',
  7 => '4',
  8 => '4', <-- This entry have value '4' : 
  14 => '8',
  17 => '2',
  21 => '8',
  25 => '6',

),
'dt_time_slot' => 
array (
  1 => '4:30',
  2 => '6:30',
  3 => '9:00',
  4 => '17:00',
  5 => '23:00',
  6 => '0:30',
  7 => '1:30',
  8 => '4:30', <-- This entry have value '4:30' : 
  14 => '4:00',
  17 => '19:00',
  21 => '6:30',
  25 => '7:30',

));

What is real duplicate means that all three different array have same keys like 1,2,3,....14,....25. what i want that same key from three arrays should not contain same value...if they contain same then i marked it as duplicates..

What I want is to remove duplicate entries from the three different array (duplicate entries can be greater than 3. This time its 3.) and keep only one value.

Please let me know how can I do that.

share|improve this question
    
So what would the result be here? And what's the "duplicate" based on? I see no real pattern why those particular items you marked are duplicates and others are not. –  deceze 19 hours ago
    
I know this is not pattern. but i am getting this result with three different array named "table_id","no_of_seats","dt_time_slot". What is real duplicate means that all three different array have same keys like 1,2,3,....14,....25. what i want that same key from three arrays should not contain same value...if they contain same then i marked it as duplicates.. –  Sunil Jindal 19 hours ago
    
have i asked anything wrong which you are not getting??? –  Sunil Jindal 19 hours ago
add comment

1 Answer

You can use array_unique http://www.php.net/manual/en/function.array-unique.php

   $array['table_id'] = array_unique($array['table_id']);
   $array['no_of_seats'] = array_unique($array['no_of_seats']);
   ...etc
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.