/ / PHP - Pourquoi cela retourne un tableau multi-dimensionnel? - php, html, tableau multidimensionnel

PHP - Pourquoi cela retourne un tableau multidimensionnel? - php, html, multidimensionnel-array

Bonjour, j'ai ce code et il (records2) renvoie un tableau multi-dimensionnel pour une raison quelconque., Quelqu'un peut-il m'aider et indiquer pourquoi? J'ai besoin d'un tableau simple, à une seule dimension.

function getBook() {
global $dbc;
global $id;
//connect to database
require("db.php");
//make the query
$query = "SELECT title, fiction, publisher, summary, pages FROM bookShelf WHERE id=$id;";
$runQuery = @mysqli_query($dbc, $query); //run the query


$records2 = array();
while ($row = mysqli_fetch_assoc($runQuery)) {
$records2[] = $row;
}
echo "<pre>";
print_r($records2);
echo "</pre>";
}

Réponses:

-1 pour la réponse № 1
$records2 = array();
$records2 = mysqli_fetch_assoc($runQuery);

Ici, la fonction mysqli_fetch_assoc () extrait une ligne de résultat sous la forme d'un tableau associatif à une seule dimension, sans aucune boucle.