0

I have a multi-dimensional array and php seems to be returning an array instead of a value when I attempt to access the values directly. What am I doing to cause this?

The array looks like (via print_r):

Array ( 
[12] => Array ( [2016] => 93083.00 [2015] => 85367.00 [2014] => 69726.00 ) 
[11] => Array ( [2016] => 66730.00 [2015] => 65548.00 [2014] => 77936.00 ) 
[10] => Array ( [2016] => 84602.00 [2015] => 112070.00 [2014] => 102104.00 )
 )

I'm trying to access values using $arrayname[12][2016] but it is returning Array[2016] instead of 93083.

Is this a simple syntax mistake? Or am I missing part of the concept here? I've been trying to work this problem for hours so maybe I'm missing a simple explanation.

EDIT: the syntax above is actually correct, the issue was in the data entry: I was trying to access a key that didn't exist. I tried to delete the post, but can't since it has been answered.

4
  • 6
    Please show how you're attempting to print it out, because that is correct. Commented Aug 14, 2017 at 17:57
  • echo $chart3_array[1][2017]; doesn't output anything, while print_r($chart3_array); does. Commented Aug 14, 2017 at 18:02
  • Could this possibly be a type issue with the second key? I've tried it both as 2017 and "2017" though. Commented Aug 14, 2017 at 18:03
  • I found it, it was an error in the data being entered. Thanks for your help. I will delete the question shortly. Commented Aug 14, 2017 at 18:04

1 Answer 1

1
$arrayname[12] = [2016=>93083.00,  2015=> 85367.00 ] 
    ...
    ...
    echo $arrayname[12][2015] ; // prints 85367

i think your array has one more level. try $arrayname[12][2016][2016] .

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

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.