scopeak
scopeak

Reputation: 545

Accessing specific meta fields from a PHP array

I am using the following to output meta values for a current logged in user.

<?php
$user_id = get_current_user_id();
$key = 'chargebee_user_subscriptions';
$all_meta_for_user = get_user_meta( $user_id, $key, true  );
print_r($all_meta_for_user);

Output

Array ( [0] => Array ( [subscription_id] => IaQX8AtBRo [product_id] => cbdemo_grow [product_name] => Plan - Grow [product_decs] => This a 3-month plan with a 14 day trial period. [status] => in_trial [product_price] => 89 USD / 3 month [trail_start] => 08/02/2018 [trial_end] => 22/02/2018 ) )

This works great, but I only need to access a specific meta field from the array product_id.

I've attempted to output this via the following but cannot get it to work:

<?php
$all_meta_for_user['product_id'][0];

Upvotes: 0

Views: 103

Answers (2)

Ajeet
Ajeet

Reputation: 286

You are accessing the array in a wrong way. Try the following:

$all_meta_for_user[0]['product_id'];

Upvotes: -1

gonzie
gonzie

Reputation: 203

You have it the wrong way around.

$all_meta_for_user[0]['product_id'];

Upvotes: 2

Related Questions