0
我有這行代碼的工作:PHP與陣列
print_r(get_the_terms($_product->id, 'product_cat'));
返回:
Array ([0] => stdClass Object ([term_id] => 67 [name] => Paintings [slug] => paintings [term_group] => 0 [term_taxonomy_id] => 67 [taxonomy] => product_cat [description] => [parent] => 0 [count] => 44) [1] => stdClass Object ([term_id] => 13 [name] => Small [slug] => small [term_group] => 0 [term_taxonomy_id] => 13 [taxonomy] => product_cat [description] => [parent] => 0 [count] => 15))
什麼,我想獲得的[名] =>繪畫,所以我可以創建另一個數組像這樣:
$array[get_the_terms($_product->id, 'product_cat')->name] = $_product->get_title()
$_product->get_title()
是 「安靜的一天」
expected output Array ([Paintings] => A Quiet Day)
如果我這樣做:
$array[] = $_product->get_title();
輸出
Array ([0] => A Quiet Day)
我只是想如果你想用繪畫