I need to find the average of all AdjClose
values in my two dimensional array.
I have an array stored in a variable $data
. It looks like this:
["data"]=>
array(22) {
[0]=>
object(stdClass)#234 (7) {
["Date"]=>
string(10) "2016-08-31"
["Open"]=>
string(9) "767.01001"
["High"]=>
string(10) "769.090027"
["Low"]=>
string(10) "765.380005"
["Close"]=>
string(10) "767.049988"
["Volume"]=>
string(7) "1247400"
["AdjClose"]=>
string(10) "767.049988"
}
[1]=>
object(stdClass)#240 (7) {
["Date"]=>
string(10) "2016-08-30"
["Open"]=>
string(10) "769.330017"
["High"]=>
string(10) "774.466003"
["Low"]=>
string(10) "766.840027"
["Close"]=>
string(10) "769.090027"
["Volume"]=>
string(7) "1127100"
["AdjClose"]=>
string(10) "769.090027"
}
It has around 22 entries and I want to iterate through every ["AdjClose"] and calculate the average of these numbers.
From what I understand, I should write something like:
if(@$data->data->AdjClose)
but this is where my problems begin.
Can someone explain to me please how to iterate through the objects/rows access and store the AdjClose values and calculate the average?