加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

从数组PHP中提取[cat_ID]

发布时间:2020-12-13 22:52:31 所属栏目:PHP教程 来源:网络整理
导读:我有以下数组(只是完整数组的一部分),我想提取[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] =
我有以下数组(只是完整数组的一部分),我想提取[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
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读