本文介绍了从包含对象数组多维获得价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何从这个数组得到[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 }
更多推荐
从包含对象数组多维获得价值
发布评论