【发布时间】:2018-01-11 19:11:59
【问题描述】:
如何在逗号分隔的多维数组上使用id添加链接?
到目前为止我做了什么:
$string = implode(", ", array_column($title_genres, "name"));
echo $string;
我的数组:
array(4) {
[0]=>
object(stdClass)#66 (3) {
["id"]=>
string(2) "21"
["name"]=>
string(8) "Aventure"
["tmdb_id"]=>
string(2) "12"
}
[1]=>
object(stdClass)#67 (3) {
["id"]=>
string(2) "20"
["name"]=>
string(9) "Animation"
["tmdb_id"]=>
string(2) "16"
}
[2]=>
object(stdClass)#63 (3) {
["id"]=>
string(1) "8"
["name"]=>
string(8) "Familial"
["tmdb_id"]=>
string(5) "10751"
}
[3]=>
object(stdClass)#70 (3) {
["id"]=>
string(1) "9"
["name"]=>
string(11) "Fantastique"
["tmdb_id"]=>
string(2) "14"
}
}
【问题讨论】:
-
不知道你在问什么
-
在 php7 array_column 中使用对象。在您通过
$x->name收集值之前 -
你想要什么结果?有样品吗?
-
这里是我想要的结果“冒险、动画、家族、奇幻”
-
您是否询问如何将每个
name包装在a标记中,并将id作为hrefurl 的一部分?
标签: php