问题
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