在这里,我有以下变量 $countries_all:
Array (
[0] => stdClass Object
(
[countries] => India,Afghanestan,Japan,South Africa
)
[1] => stdClass Object
(
[countries] => Singapore,South Africa,India,Pakistan
)
[2] => stdClass Object
(
[countries] => Japan,Australia,India
)
)
但我需要创建第二个数组 $countries 只包含唯一值:
Array (
[0] => stdClass Object
(
[countries] => India
)
[1] => stdClass Object
(
[countries] => Afghanestan
)
[2] => stdClass Object
(
[countries] => Japan
)
[3] => stdClass Object
(
[countries] => South Africa
)
[4] => stdClass Object
(
[countries] => Singapore
)
[5] => stdClass Object
(
[countries] => Pakistan
)
[6] => stdClass Object
(
[countries] => Japan
)
[7] => stdClass Object
(
[countries] => Australia
)
)
对于按 (,) 分割,我使用了以下方法
foreach ($countries_all as $list){
$countrieslist=explode(',', $list->countries);
foreach ($countrieslist as $uni_countries){
echo $uni_countries;
}
}
但是如何从上述案例中获取唯一值。
谁能帮助我
提前致谢。
编辑1
在这里,我还有一个与上述问题相关的查询。
现在我得到了独特的价值观,
我如何从该唯一值的数据库中获取结果
例如,我想要所有具有(喜欢)国家为“印度”的结果