dongluo6343 2014-04-24 11:07
浏览 11

从不同的数组php删除重复值

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.

  • 写回答

1条回答 默认 最新

  • 普通网友 2014-04-24 11:10
    关注

    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
    
    评论

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch