3v4l.org

run code in 300+ PHP versions simultaneously
<?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);

preferences:
16.3 ms | 402 KiB | 5 Q