从包含对象数组多维获得价值

编程入门 行业动态 更新时间:2024-10-26 16:29:43
本文介绍了从包含对象数组多维获得价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我如何从这个数组得到[USER_ID]

阵列(      [2] => cbpaidSubscription对象        (            [replaces_plan] =>        [replaces_subscription] =>        [subscription_date] => 2009-07-14 12点45分52秒        [last_renewed_date] => 2009-07-14 12点45分52秒        [EXPIRY_DATE] => 2010-07-14 12点45分52秒        [autorenew_type] => 2        [autorecurring_type] => 2        [regular_recurrings_total] => 0        [regular_recurrings_used] => 1        [previous_expiry_date] =>        [previous_status] => - [R        [previous_recurrings_used] => 0        [ip_addresses] => 127.0.0.1        [ID] => 2        [现状] =>一个        [USER_ID] => 71        [plan_id的数据类型] => 1        [parent_plan] => 0        [parent_subscription] => 0        [积分] =>        [_plan] => cbpaidProductusersubscription对象            (

解决方案

如果你能保证该数组只有一个项目,你知道密钥,然后用乔纳森·桑普森的解决方案去了。否则,如果你有一个这样可以循环的几个项目上并提取用户标识的每一个。

的foreach($数组作为$项目){    $用户id = $本期特价货品> USER_ID;    //为这个项目做的用户id的东西}

how can i get [user_id] from this array?

Array ( [2] => cbpaidSubscription Object ( [replaces_plan] => [replaces_subscription] => [subscription_date] => 2009-07-14 12:45:52 [last_renewed_date] => 2009-07-14 12:45:52 [expiry_date] => 2010-07-14 12:45:52 [autorenew_type] => 2 [autorecurring_type] => 2 [regular_recurrings_total] => 0 [regular_recurrings_used] => 1 [previous_expiry_date] => [previous_status] => R [previous_recurrings_used] => 0 [ip_addresses] => 127.0.0.1 [id] => 2 [status] => A [user_id] => 71 [plan_id] => 1 [parent_plan] => 0 [parent_subscription] => 0 [integrations] => [_plan] => cbpaidProductusersubscription Object (

解决方案

If you can guarantee that the array only has one item and you know the key, then go with Jonathan Sampson's solution. Otherwise if you have a few items you can loop over it like this and extract the userid for each one.

foreach ($array as $item) { $userId = $item->user_id; //do something with the userId for this item }

更多推荐

从包含对象数组多维获得价值

本文发布于:2023-11-26 22:12:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635407.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多维   数组   对象   价值

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!