How can PHP arrays be used to organize and display database content in a structured manner?

To organize and display database content in a structured manner using PHP arrays, you can fetch the data from the database and store it in an array. You can then iterate over the array to display the content in a structured format, such as a table or a list.

// Connect to the database
$connection = mysqli_connect('localhost', 'username', 'password', 'database');

// Query to fetch data from the database
$query = "SELECT * FROM table";
$result = mysqli_query($connection, $query);

// Fetch data and store it in an array
$data = array();
while ($row = mysqli_fetch_assoc($result)) {
    $data[] = $row;
}

// Display data in a structured format
echo '<table>';
foreach ($data as $row) {
    echo '<tr>';
    foreach ($row as $key => $value) {
        echo '<td>' . $key . ': ' . $value . '</td>';
    }
    echo '</tr>';
}
echo '</table>';