How can the error "Cannot use object of type mysqli_result as array" be resolved in PHP?

The error "Cannot use object of type mysqli_result as array" occurs when trying to access a result set from a MySQL query as an array directly. To resolve this issue, you need to fetch the data from the mysqli_result object using a method like fetch_assoc() or fetch_array() before trying to access it as an array.

// Example of resolving "Cannot use object of type mysqli_result as array" error
$query = "SELECT * FROM table_name";
$result = $mysqli->query($query);

// Fetch data from mysqli_result object
while ($row = $result->fetch_assoc()) {
    // Access data as an array
    echo $row['column_name'];
}