How can PHP developers efficiently store and access multiple values from a database query result in PHP arrays?
When fetching multiple values from a database query result in PHP, developers can efficiently store and access them by using PHP arrays. By looping through the query result and storing each row as an array element, developers can easily access and manipulate the data as needed.
// Assume $result contains the database query result
$data = array(); // Initialize an empty array to store the fetched data
while ($row = $result->fetch_assoc()) {
$data[] = $row; // Store each row as an array element in $data
}
// Accessing the stored data
foreach ($data as $row) {
// Access individual values using array keys
echo $row['column_name'];
}