How to show two arrays of a variable - PHP

Asked

Viewed 75 times

0

I am learning to work with PHP and I would like to know how to show two arrays of a single variable.

I am making a selection of the bank that sends me two arrays, I would like to know how to show them.

In the $res variable comes two arrays, and I would like to show the key and the value. With foreach works, but brings only one array.

$sql = "SELECT * FROM formulario;";

$res = mysqli_query($mysqli, $sql);

$exibe = mysqli_fetch_assoc($res);

if ($res == false) {
   header("Location: erro.php");
}
?>

<!DOCTYPE html>
<html lang="pt-br" dir="ltr">
<head>
    <meta charset="utf-8">
    <title>index PHP</title>
</head>
<body>

    <form action="inserir/form-inserir.php" method="post">

        <?php foreach ($exibe as $chave => $valor) { ?>
            <h2> <?= $chave ?> </h2>
            <h4> <?= $valor ?> </h4>
        <?php } ?>

    </form>
    <form action="../index.php" method="post">
        <h1></h1>

        <input type="submit" value="Voltar ao index">
    </form>
</body>

  • And what would be the "two arrays"? How do you want to display?

  • Does the above code present an error? You are displaying the key and the value of the associative array, theoretically it is correct.

  • In the $res variable comes two arrays, and I would like to show the key and the value. With foreach works, but brings only one array.

1 answer

0

Got it, got it:

<?php while ($exibe = mysqli_fetch_assoc($res)) { ?>
     <?php foreach ($exibe as $chave => $valor) { ?>
         <h2> <?= $chave ?> </h2>
         <h4> <?= $valor ?> </h4>
     <?php } ?>
<?php } ?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.