How can PHP arrays be effectively utilized to iterate through user data and make status updates based on specific criteria, such as inactivity periods?

To iterate through user data and make status updates based on specific criteria, such as inactivity periods, you can utilize PHP arrays to store and manipulate the user information. By looping through the array and checking for conditions like inactivity periods, you can update the user status accordingly.

<?php
// Sample user data array
$users = [
    ['id' => 1, 'name' => 'John', 'last_activity' => '2022-01-01'],
    ['id' => 2, 'name' => 'Jane', 'last_activity' => '2022-02-15'],
    ['id' => 3, 'name' => 'Alice', 'last_activity' => '2022-03-20'],
];

// Define inactivity period threshold (e.g. 30 days)
$inactivity_period = 30;

// Loop through users array
foreach ($users as $user) {
    $last_activity_date = new DateTime($user['last_activity']);
    $current_date = new DateTime();
    $interval = $last_activity_date->diff($current_date)->days;
    
    if ($interval > $inactivity_period) {
        echo "{$user['name']} is inactive for more than {$inactivity_period} days. Updating status...\n";
        // Add code here to update user status
    }
}
?>