gpt4 book ai didi

php - 从每个数组中回显特定行

转载 作者:行者123 更新时间:2023-12-05 08:57:15 27 4
gpt4 key购买 nike

我有以下动态生成的数组。数组值每次都可以更改,但位置保持不变(即名称将始终是每个数组的第二项)。

我如何从每个数组中回显相同的特定行?例如,假设我想要所有的名字一起呼应?

Array
(
[0] => WP_Term Object
(
[term_id] => 437
[name] => 128 GB
[slug] => 128-gb
[term_group] => 0
[term_taxonomy_id] => 437
[taxonomy] => pa_phone-capacity
[description] =>
[parent] => 0
[count] => 88
[filter] => raw
)

[1] => WP_Term Object
(
[term_id] => 19
[name] => AT&T
[slug] => att
[term_group] => 0
[term_taxonomy_id] => 19
[taxonomy] => pa_phone-carrier
[description] =>
[parent] => 0
[count] => 288
[filter] => raw
)

[2] => WP_Term Object
(
[term_id] => 280
[name] => Flawless
[slug] => flawless
[term_group] => 0
[term_taxonomy_id] => 280
[taxonomy] => pa_phone-condition
[description] => Works perfectly.

No noticeable flaws, still in its package or looks like new.

Has zero scratches or scuffs.
[parent] => 0
[count] => 338
[filter] => raw
)

[3] => WP_Term Object
(
[term_id] => 442
[name] => iPhone
[slug] => iphone
[term_group] => 0
[term_taxonomy_id] => 442
[taxonomy] => pa_device
[description] =>
[parent] => 0
[count] => 496
[filter] => raw
)

[4] => WP_Term Object
(
[term_id] => 284
[name] => iPhone 6 Plus
[slug] => iphone-6-plus
[term_group] => 0
[term_taxonomy_id] => 284
[taxonomy] => pa_phone-model
[description] =>
[parent] => 0
[count] => 72
[filter] => raw
)

[5] => WP_Term Object
(
[term_id] => 443
[name] => Smartphone
[slug] => smartphone
[term_group] => 0
[term_taxonomy_id] => 443
[taxonomy] => pa_device
[description] =>
[parent] => 0
[count] => 1352
[filter] => raw
)

我需要一个将保持动态的解决方案。有时可能有 8 个术语对象,有时可能只有 5 个,就像上面的数组一样。 term_id 永远是第一个,name 永远是第二个,依此类推。

这已经困扰我至少一个小时了,这让我非常沮丧:(

最佳答案

echo implode(", ", array_map(function(WP_Term $term){
return $term->name;
}, $array));

关于php - 从每个数组中回显特定行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34566244/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com