Get value from Multidimentional Array containing an Object

后端 未结 2 1902
小蘑菇
小蘑菇 2021-01-27 09:07

how can i get [user_id] from this array?

Array  
(  
      [2] => cbpaidSubscription Object  
        (  
            [replaces_plan] =>   
        [replac         


        
相关标签:
2条回答
  • 2021-01-27 09:30

    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
    }
    
    0 讨论(0)
  • 2021-01-27 09:38

    I'm thinking...

    print $arrayName[2]->user_id;
    
    0 讨论(0)
提交回复
热议问题