I am new in PHP. I am trying to get some value from json file and following This Stackoverflow answer
When I run example given in answer working fine.
I have my.json file like below
{
"quoteSummary": {
"result": [
{
"summaryDetail": {
"maxAge": 1,
"priceHint": {
"raw": 2,
"fmt": "2",
"longFmt": "2"
},
"previousClose": {
"raw": 126,
"fmt": "126.00"
},
"navPrice": {},
"currency": "USD",
"fromCurrency": null,
"toCurrency": null,
"lastMarket": null,
"volume24Hr": {},
"volumeAllCurrencies": {},
"circulatingSupply": {},
"algorithm": null,
"maxSupply": {},
"startDate": {},
"tradeable": false
},
"defaultKeyStatistics": {
"maxAge": 1,
"priceHint": {
"raw": 2,
"fmt": "2",
"longFmt": "2"
},
"lastDividendDate": {
"raw": 1612483200,
"fmt": "2021-02-05"
},
"lastCapGain": {},
"annualHoldingsTurnover": {}
},
"earnings": {
"maxAge": 86400,
"earningsChart": {
"quarterly": [
{
"date": "1Q2020",
"actual": {
"raw": 0.64,
"fmt": "0.64"
},
"estimate": {
"raw": 0.56,
"fmt": "0.56"
}
},
{
"date": "2Q2020",
"actual": {
"raw": 0.64,
"fmt": "0.64"
},
"estimate": {
"raw": 0.51,
"fmt": "0.51"
}
}
],
"currentQuarterEstimate": {
"raw": 0.98,
"fmt": "0.98"
},
"currentQuarterEstimateDate": "1Q",
"currentQuarterEstimateYear": 2021,
"earningsDate": [
{
"raw": 1619568000,
"fmt": "2021-04-28"
},
{
"raw": 1620000000,
"fmt": "2021-05-03"
}
]
},
"financialsChart": {
"yearly": [
{
"date": 2017,
"revenue": {
"raw": 229234000000,
"fmt": "229.23B",
"longFmt": "229,234,000,000"
},
"earnings": {
"raw": 48351000000,
"fmt": "48.35B",
"longFmt": "48,351,000,000"
}
},
{
"date": 2018,
"revenue": {
"raw": 265595000000,
"fmt": "265.6B",
"longFmt": "265,595,000,000"
},
"earnings": {
"raw": 59531000000,
"fmt": "59.53B",
"longFmt": "59,531,000,000"
}
},
{
"date": 2019,
"revenue": {
"raw": 260174000000,
"fmt": "260.17B",
"longFmt": "260,174,000,000"
},
"earnings": {
"raw": 55256000000,
"fmt": "55.26B",
"longFmt": "55,256,000,000"
}
},
{
"date": 2020,
"revenue": {
"raw": 274515000000,
"fmt": "274.51B",
"longFmt": "274,515,000,000"
},
"earnings": {
"raw": 57411000000,
"fmt": "57.41B",
"longFmt": "57,411,000,000"
}
}
],
"quarterly": [
{
"date": "1Q2020",
"revenue": {
"raw": 58313000000,
"fmt": "58.31B",
"longFmt": "58,313,000,000"
},
"earnings": {
"raw": 11249000000,
"fmt": "11.25B",
"longFmt": "11,249,000,000"
}
},
{
"date": "2Q2020",
"revenue": {
"raw": 59685000000,
"fmt": "59.69B",
"longFmt": "59,685,000,000"
},
"earnings": {
"raw": 11253000000,
"fmt": "11.25B",
"longFmt": "11,253,000,000"
}
},
{
"date": "3Q2020",
"revenue": {
"raw": 64698000000,
"fmt": "64.7B",
"longFmt": "64,698,000,000"
},
"earnings": {
"raw": 12673000000,
"fmt": "12.67B",
"longFmt": "12,673,000,000"
}
},
{
"date": "4Q2020",
"revenue": {
"raw": 111439000000,
"fmt": "111.44B",
"longFmt": "111,439,000,000"
},
"earnings": {
"raw": 28755000000,
"fmt": "28.75B",
"longFmt": "28,755,000,000"
}
}
]
},
"financialCurrency": "USD"
}
}
],
"error": null
}
}
I am trying to run like below
$json = file_get_contents('my.json');
$data = json_decode($json, true);
echo $data['quoteSummary']['result']['summaryDetail']['priceHint']['raw'];
but its giving me warning like
Notice: Undefined index: summaryDetail in C:\xampp\htdocs\index.php on line 6
Basically I am looking for get below values from my json file
From summaryDetail, I want
maxAge
priceHint->raw
From defaultKeyStatistics, I want
lastDividendDate->raw
and From Earning, I want
earningsChart->quarterly->actual->raw
Let me know if anyone can help me for same. I am trying from last hour but not able to get idea what I should do .
Thanks!