gpt4 book ai didi

php - 从数组 PHP 中提取 [cat_ID]

转载 作者:可可西里 更新时间:2023-10-31 23:40:34 25 4
gpt4 key购买 nike

我有以下数组(只是完整数组的一部分),我想提取 [cat_ID] 的值。

Array ([1] => stdClass Object ( [term_id] => 21 [name] => z_aflyst [slug] => z_aflyst
[term_group] => 0 [term_taxonomy_id] => 23 [taxonomy] => category
[description] => [parent] => 0 [count] => 1 [object_id] => 7 [cat_ID] => 21
[cat_name] => z_aflyst ))

所以在这种情况下我需要提取 21。但是,如果 cat_name 等于 z_aflyst,我只想提取 cat_ID

最佳答案

假设您有一个对象数组:

Array (
[1] => stdClass Object
(
[term_id] => 21
[name] => z_aflyst
[slug] => z_aflyst
[term_group] => 0
[term_taxonomy_id] => 23
[taxonomy] => category
[description] =>
[parent] => 0
[count] => 1
[object_id] => 7
[cat_ID] => 21
[cat_name] => z_aflyst )
)

foreach ($items as $item)
{
if($item->cat_name == 'z_aflyst')
{
//do stuff
}
}

关于php - 从数组 PHP 中提取 [cat_ID],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23515405/

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