How can the PHP script be optimized to improve performance and readability?

The PHP script can be optimized by using proper coding practices such as avoiding unnecessary loops and function calls, utilizing built-in PHP functions efficiently, and organizing the code in a more readable and structured manner. By refactoring the code to eliminate redundancy and improve readability, the script's performance can be enhanced.

// Original code snippet
$users = getUsers(); // Assume this function retrieves user data from a database

foreach ($users as $user) {
    if ($user['age'] > 18) {
        // Perform some operation
    }
}

// Optimized code snippet
$adultUsers = array_filter($users, function($user) {
    return $user['age'] > 18;
});

foreach ($adultUsers as $user) {
    // Perform the same operation as before
}