0

How do I reference the price in the last branch?

I have tried $arr['lines']['line1']['price'], but I got an error. What is the correct way o referencing?

 array (size=100)
0 => 
array (size=34)
  'id' => string '1' (length=1)
  'invoicenr_full' => string 'dsf' (length=7)
  'invoicenr' => string 'fsd' (length=7)
  'reference' => 
    array (size=3)
      'line1' => string 'fsde' (length=20)
      'line2' => string 'sfsdfd' (length=31)
      'line3' => string 'dfsds' (length=45)
  'lines' => 
    array (size=1)
      'line1' => 
        array (size=7)
          'amount' => string '1' (length=1)
          'amount_desc' => string '' (length=0)
          'description' => string 'sdfsdf'
          'tax_rate' => string '21' (length=2)
          'price' => string '150' (length=3)
          'discount_pct' => int 0
          'linetotal' => int 150

3 Answers 3

3

If this is an accurate description of the structure: $arr[0]['lines']['line1']['price']

where 0 is the index of the first level.

Sign up to request clarification or add additional context in comments.

Comments

1

To access your element, you could to the following :

$price = $arr[0]['lines']['line1']['price'];

Also if your first level "[0]" is useless you could use array_shift($arr);

Then you would access your elem like this :

$price = $arr['lines']['line1']['price'];

Comments

0

If you don't want to use the zero index you can also use array_shift

$theArray = array_shift($theArray);

This will allow you to access any array element and you don't have to use the first element "[0]" key like so:

$theArray['lines']['line1']['price']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.