如何合併相同的數組鍵,但數值不同。 我用我的代碼輸出值如下:如何合併相同的數組鍵,但數值不同。
西甲Division2016-17,2017-18國王杯Ray2016-17
但是當我回聲出我的代碼,然後我得到輸出如下:
西甲Division2017-18國王杯Ray2016-17西甲 Division2016-17
你能看兩次西班牙西甲賽區嗎?我想這一次,但這一年兩次。 代碼:
<?php
$champion_team = get_post_meta(get_the_ID(), 'football_league_team_name', true);
$terms_competition = get_the_terms(get_the_ID(), 'competition');
$terms_session = get_the_terms(get_the_ID(), 'session');
$cc= array_merge($terms_competition, $terms_session);
foreach ($cc as $c) {
# code...
echo $c->name;
}
?>
print_r的輸出:
WP_Term Object ([term_id] => 6 [name] => Spanish Primera Division [slug] => spanish-primera-divisioj [term_group] => 0 [term_taxonomy_id] => 6 [taxonomy] => competition [description] => [parent] => 0 [count] => 10 [filter] => raw)
WP_Term Object ([term_id] => 7 [name] => 2017-18 [slug] => 2017-18 [term_group] => 0 [term_taxonomy_id] => 7 [taxonomy] => session [description] => [parent] => 0 [count] => 4 [filter] => raw)
WP_Term Object ([term_id] => 18 [name] => Copa Del Ray [slug] => copa-del-ray [term_group] => 0 [term_taxonomy_id] => 18 [taxonomy] => competition [description] => [parent] => 0 [count] => 1 [filter] => raw)
WP_Term Object ([term_id] => 11 [name] => 2016-17 [slug] => 2016-17 [term_group] => 0 [term_taxonomy_id] => 11 [taxonomy] => session [description] => [parent] => 0 [count] => 9 [filter] => raw)
WP_Term Object ([term_id] => 6 [name] => Spanish Primera Division [slug] => spanish-primera-divisioj [term_group] => 0 [term_taxonomy_id] => 6 [taxonomy] => competition [description] => [parent] => 0 [count] => 10 [filter] => raw)
WP_Term Object ([term_id] => 11 [name] => 2016-17 [slug] => 2016-17 [term_group] => 0 [term_taxonomy_id] => 11 [taxonomy] => session [description] => [parent] => 0 [count] => 9 [filter] => raw)
謝謝。通過這種方式? –