Skip to content
Advertisement

PHP: How to print sub values from multi-level array (Stripe object)

I get the below object which returns from retrieving a Stripe session ID (the object is called $order).

I am able to print values from the first object level using e.g. print_r($order->id);

How can I print values from the second level, such as amount or currency ?
I tried print_r($order->display_items->amount); and print_r($order->display_items['amount']);

PHP:

JavaScript

Update: If I use print_r($order->display_items); I get the below. Could I assign this to an array and then print from there (if there is no other solution) ?

JavaScript

Many thanks in advance.

Advertisement

Answer

print_r($obj->display_items[0]->amount);

Just be sure your JSON is valid 🙂 https://jsonlint.com/

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement