Yeak Yeak - 4 months ago 13
PHP Question

remove duplicate array from multi dimensional array by key value

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

)

)

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

$result = array_combine($keys, array);

try it