Is it more efficient to store query results in an array or a concatenated string in PHP?

Storing query results in an array is generally more efficient and flexible than storing them in a concatenated string in PHP. Arrays allow for easier manipulation and access to individual elements, while concatenated strings can become unwieldy and harder to work with. Additionally, arrays provide built-in functions for sorting, filtering, and iterating over the data, making them a better choice for storing query results.

// Storing query results in an array
$query = "SELECT * FROM table";
$result = mysqli_query($connection, $query);
$data = array();

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

// Accessing data from the array
foreach($data as $row) {
    echo $row['column_name'] . "<br>";
}