0

I've been trying to learn PHP arrays, I have got the basic but struggling with this one.

I'm looking to try and get the value of a key "pdfUrl" by calling the key I want.

Any help would be greatly appreciated.

Array ( [0] => Clearbooks_Soap_1_0_Invoice Object ( [items] => Array ( [0] => Clearbooks_Soap_1_0_Item Object ( [description] => Line Item #1 [unitPrice] => 24.99 [vat] => 5 [quantity] => 1 [type] => 1001001 [vatRate] => 0.2 ) ) [description] => API Test Invoice [entityId] => 16 [invoice_id] => 209 [invoice_prefix] => INV [invoiceNumber] => 204 [reference] => [dateCreated] => 2012-10-19 00:00:00 [dateDue] => 2012-11-16 00:00:00 [dateAccrual] => 2012-10-19 00:00:00 [creditTerms] => 30 [bankPaymentId] => 0 [project] => 0 [external_id] => [status] => approved [pdfUrl] => https://secure.clearbooks.co.uk/accounting/sales/invoice_html/?source=statement&type=invoice&c=2&auth=-lHLOCMD8mOPS5qyEjiw2g [themeId] => 0 [type] => S [vatTreatment] => [multicurrency] => 0 [gross] => 29.99 [net] => 24.99 [vat] => 5 [paid] => 0 [balance] => 29.99 [foreignCurrencyBalance] => 0 ) ) 
1
  • Please show us what you've tried. Commented Jun 16, 2021 at 11:52

1 Answer 1

1

You start out with an array with only one object. To call this object you can use:

$nameVar[0] 

Then we have an object. You can not use '[]' for objects in PHP. Use '->' to get the value of properties of an object:

$nameVar[0]->pdfUrl 

So if we want the unitprice of the first item we use:

$nameVar[0]->items[0]->unitPrice 
Sign up to request clarification or add additional context in comments.

1 Comment

Absolute legend, thank you very much. Something so simple and I was over thinking it like crazy hahaha.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.