Get value from Multidimentional Array containing an Object

孤街醉人 提交于 2019-12-31 07:04:07

问题


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  
            (  

回答1:


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
}



回答2:


I'm thinking...

print $arrayName[2]->user_id;


来源:https://stackoverflow.com/questions/1128519/get-value-from-multidimentional-array-containing-an-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!