- array_sum: documentation ( source)
- unserialize: documentation ( source)
- serialize: documentation ( source)
- ksort: documentation ( source)
- rand: documentation ( source)
<?php
//Enter your code here, enjoy!
$firstDayInMonth = new DateTime("first day of this month");
$lastDayInMonth = new DateTime("last day of this month");
$currentDate = new DateTime();
$registryCollection = [];
/*
Better way
*/
$registryCollection = unserialize(""); // file_get_contents.. warning about ""
// 2|1. User add in current day something: - Check if something is there ! array_key_exists!
$registryCollection[$currentDate->format("d.m.Y")] = 120.0;
// Test for another day;
$otherDay = clone $currentDate;
$otherDay->modify("-7 day");
$registryCollection[$otherDay->format("d.m.Y")] = (float)rand()%199;
// Sort Array by keys
ksort($registryCollection);
// 1. User want to see all data stored:
foreach($registryCollection as $date => $money){
echo "For date: {$date} you spent: {$money} PLN\n";
}
// Sum all
$sum = array_sum($registryCollection);
echo "\nSUM: {$sum} PLN\n";
// We want to store data..
$data = serialize($registryCollection); // file_put_contents with content ->
//print_r($data);