Reputation: 383
I have an array where I'm trying to find the unique values. I've seen many answers for this type of thing, but I can't understand how to apply them to my situation. Thanks in advance for the help, as I'm learning.
Array([0] => Array ( [department] => value1)
[1] => Array ( [department] => value1)
[2] => Array ( [department] => value2)
[3] => Array ( [department] => value2)
[4] => Array ( [department] => value3)
[5] => Array ( [department] => value3))
So I want to pull out value1, value2 and value3 so I can populate them into a select box using foreach, but I am always receiving a list showing all of the instance of each value above (value1, value1, value2, value2, value3, value3).
Upvotes: 1
Views: 124
Reputation: 63442
$departments = array();
foreach ($personnel_list as $part) {
$departments[] = $part['department'];
}
$departments = array_unique($departments);
Upvotes: 7