How can PHP developers effectively utilize associative arrays to store and manipulate database query results in their code?

PHP developers can effectively utilize associative arrays to store and manipulate database query results by fetching the data from the database and storing it in an associative array where the column names are used as keys. This allows for easy access and manipulation of the data within the array.

// Assume $db is a PDO object connected to the database

// Perform a database query
$stmt = $db->query("SELECT * FROM users");

// Fetch the results as an associative array
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);

// Loop through the results and access data using column names
foreach ($results as $row) {
    echo $row['username'] . '<br>';
}