2

i have the following array

 Array
 (
[0] => Array
    (
        [id_scheduled_work] => 238
        [id_schedule_hours] => 1
        [id_truck] => 1
        [id_scheduled_work_details] => 209
        [work_order] => Z20160807211621

    )

[1] => Array
    (
        [id_scheduled_work] => 239
        [id_schedule_hours] => 2
        [id_truck] => 1
        [work_order] => Z20160807211621

    )
[2] => Array
    (
        [id_scheduled_work] => 240
        [id_schedule_hours] => 1
        [id_truck] => 1
        [id_scheduled_work_details] => 209
        [work_order] => A20160807211621

    )

[3] => Array
    (
        [id_scheduled_work] => 245
        [id_schedule_hours] => 2
        [id_truck] => 1
        [work_order] => A20160807211621

    )

  )

So i want to remove duplicate entires by work_order number so my final array should be and i also need to reset the keys so that they go 0 1 ...

  Array
 (
[0] => Array
    (
        [id_scheduled_work] => 238
        [id_schedule_hours] => 1
        [id_truck] => 1
        [id_scheduled_work_details] => 209
        [work_order] => Z20160807211621

    )
[1] => Array
    (
        [id_scheduled_work] => 240
        [id_schedule_hours] => 1
        [id_truck] => 1
        [id_scheduled_work_details] => 209
        [work_order] => A20160807211621

    )

)
Yeak
  • 2,470
  • 9
  • 45
  • 71
  • 3
    Possible duplicate of [How to remove duplicate values from a multi-dimensional array in PHP](http://stackoverflow.com/questions/307674/how-to-remove-duplicate-values-from-a-multi-dimensional-array-in-php) – jitendrapurohit Aug 08 '16 at 04:46
  • i looked at that but that seems to just move anything thats duplicated i need to specifically remove duplicates with work order only that match each other – Yeak Aug 08 '16 at 05:04

1 Answers1

1
$key = array_column(array, 'work_order');

$result = array_combine($keys, array);

try it

Darren
  • 13,050
  • 4
  • 41
  • 79
chenxi
  • 26
  • 2