I need to display values from [dr-spec] array below and filter duplicates:
Array
(
[0] => Array
(
[dr-spec] => Array
(
[0] => Oncology
)
)
[1] => Array
(
[dr-spec] => Array
(
[0] => Plastic Surgery
[1] => Dental
)
)
[2] => Array
(
[dr-spec] => Array
(
[0] => Oncology
[1] => Plastic Surgery
)
)
)
After two days of trials and errors I made this:
<?php
foreach( $attributes['doctor'] as $doctor ): // Loop through the top array
foreach( $doctor['dr-spec'] as $spec ): // Loop through the dr-spec array
$result[] = $spec; // assign string into a new array
endforeach;
endforeach;
$result = array_unique($result); // filter duplicates inside the array
foreach( $result as $result ):
echo $result // html ommitted
<?php endforeach; ?>
Maybe there's a better (compact) way of doing it?
Any help appreciated.