Is it advisable to use associative arrays to store and manipulate database query results in PHP?

When dealing with database query results in PHP, it is advisable to use associative arrays to store and manipulate the data. Associative arrays allow you to access the data using meaningful keys, making it easier to work with the results. This approach also provides a more structured and organized way to handle the data, improving readability and maintainability of your code.

// Example of using associative arrays to store and manipulate database query results
$query = "SELECT * FROM users";
$result = mysqli_query($connection, $query);

$data = array();

while ($row = mysqli_fetch_assoc($result)) {
    $data[] = $row;
}

// Accessing data from the associative array
foreach ($data as $user) {
    echo "User ID: " . $user['id'] . " | Name: " . $user['name'] . "<br>";
}