I know there are a lot of similar question as this one on here but the problem I keep running into is that the method in which those other json file arrays are setup is not the same as mine.
What I am trying to do should just be a simple process but as I am not as versed in json arrays and I am other things, the solution is eluding me completely.
I just want to take the data display in a local json file and create PHP variables for each item returned.
The json file is simple and looks something like this...
[
{
"titleOne": "Foo",
"textOne": "Bar",
"titleTwo": "Foo",
"textTwo": "Bar"
}
]
$data = file_get_contents ('./data.json');
$json = json_decode($data, true);
foreach ($json as $key => $value) {
foreach ($value as $key => $val) {
echo $key . '====>' . $val . '<br/>';
}
}
$titleOne
$textOne
$titleTwo
$textTwo
Why not simply define if it's always only 4:
$titleOne = $json[0]['titleOne'];
$textOne = $json[0]['textOne'];
$titleTwo = $json[0]['titleTwo'];
$textTwo = $json[0]['textTwo'];