如何转换此数组:
的print_r($ ARR)
Array (
[131] => stdClass Object
(
[tid] => 131
[vid] => 9
[name] => apple
[description] =>
[weight] => 0
)
[112] => stdClass Object
(
[tid] => 112
[vid] => 9
[name] => cool
[description] =>
[weight] => 0
)
[113] => stdClass Object
(
[tid] => 113
[vid] => 9
[name] => wonderful
[description] =>
[weight] => 0
)
)
进入这个:
apple cool wonderful
基本上取出数组的“name”变量并按顺序将其内爆。 我试过内爆,但我不知道如何只引用“名称”变量。
答案 0 :(得分:2)
echo join(" ", array_map(create_function('$x', 'return $x->name;'), $arr));
是一种方法吗
答案 1 :(得分:0)
$terms = array();
foreach($arr as $term) { $terms[] = $term->name; }
print implode($terms, ', ');