I make an event list with a maximum of 4 events, saved in its own jason files.
I wrote this code for the output.
JSON:
{"field1":"new york","field2":"1553404200","field3":1554415200}
CODE:
$jsonA = file_get_contents('code/data1.json');
$fieldsA = json_decode($jsonA, true);
$cityA = $fieldsA["field1"];
$dateStartA = $fieldsA["field2"];
$dateEndA = $fieldsA["field3"];
$jsonB = file_get_contents('code/data2.json');
$fieldsB = json_decode($jsonB, true);
$cityB = $fieldsB["field1"];
$dateStartB = $fieldsB["field2"];
$dateEndB = $fieldsB["field3"];
<div><?php echo $cityA . $dateStartA . " - " . $dateEndA?></div>
<div><?php echo $cityB . $dateStartB . " - " . $dateEndB?></div>
The problem is:
I have 4 events with each start and end date. So I have to do the same 8 times, but I do not want and should copy this code 8 times with a higher variable name... In my project I have 13 fields and also 2 arrays to output the day and month name in my language. That's why it's so important not to copy everything 8 times. I need a loop, but I do not know exactly how. I'm an absolute beginner, so please as simple as possible.