Возьмите новый массив $departments
Цикл по указанному массиву.
Добавьте department
к $departments
.
Используйте department
в качестве ключа.
Поскольку массивы PHP всегда имеют уникальные ключи, вы получите только уникальные отделы.
Рабочий код:
<code><?php
$arr = [
[
'department_id' => 15 ,'department_name' => 'R&D' ,'name' => 'SUBRAMANIAN' ,'code' => 101
,'clockin' => '' ,'late' => '' ,'date' => '1970-01-01'
],
[
'department_id' => 3 ,'department_name' => 'Manufacturing' ,'name' => 'RAVI' ,'code' => 103
,'clockin' => '' ,'late' => '' ,'date' => '1970-01-01'
],
[
'department_id' => 3 ,'department_name' => 'Manufacturing' ,'name' => 'AMULRAJAN.A' ,'code' => 104
,'clockin' => '' ,'late' =>'' ,'date' => '1970-01-01'
],
[
'department_id' => 3 ,'department_name' => 'Manufacturing' ,'name' => 'KANAKARAJ.R' ,'code' => 105
,'clockin' => '' ,'late' => '' ,'date' => '1970-01-01'
],
[
'department_id' => 3 ,'department_name' => 'Manufacturing' ,'name' => 'ELAYARAJA' ,'code' => 106
,'clockin' => '' ,'late' => ''
]];
$departments = '';
if (! empty($arr)) {
foreach ($arr as $elem) {
$departments[$elem['department_name']] = $elem['department_name'];
}
}
echo '<pre>';print_r($departments);echo '
';
Выходы:
Array
(
[R&D] => R&D
[Manufacturing] => Manufacturing
)