function updateTimeInRest() { global $usersInRestaurants; $secondsToMinutes = 60; $deletedUsers = 0; $deletedRests = 0; $minutes = 10; $nowInMinutes = round(microtime(true)) / $secondsToMinutes; foreach ($usersInRestaurants as $restId => $restDetails) { foreach ($restDetails['users'] as $userEmail => $timeOfArrival) { if ($nowInMinutes - $timeOfArrival / $secondsToMinutes >= $minutes) { unset($usersInRestaurants[$restId]['users'][$userEmail]); $deletedUsers += 1; echo nl2br("Removed " . $userEmail . " from " . $restId . "\n"); } } if (count($usersInRestaurants[$restId]['users']) == 0) { unset($usersInRestaurants[$restId]); $deletedRests += 1; echo nl2br("Deleted restaurant " . $restId . " from usersInRestaurants as it has no users inside\n\n"); } } updateGlobalVar('usersInRestaurants', $usersInRestaurants); echo nl2br("\n*** Clean up of older than " . $minutes . " minutes was finished ***\n** Deleted total of " . $deletedUsers . " users and " . $deletedRests . " restaurants **\n"); }
function updateUsersInRestField($restId, $fieldName, $value) { global $usersInRestaurants; $usersInRestaurants[$restId][$fieldName] = $value; updateGlobalVar('usersInRestaurants', $usersInRestaurants); }