我需要显示下面的 [dr-spec] 数组中的值并过滤重复项:
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
)
)
)
经过两天的尝试和错误,我做了这个:
<?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; ?>
也许有更好的(紧凑的)方法来做到这一点?
猛跑小猪