Get value from Multidimentional Array containing an Object

后端 未结 2 1926
小蘑菇
小蘑菇 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
    }
    

提交回复
热议问题