Duplicate data in the response of a query

0

Here is the code:     

$conn = new PDO('mysql:host=localhost;dbname=locadora','root','');

$resul =  $conn->query("SELECT * FROM usuario");

echo "<pre>";
$resul = $resul->fetchAll();

?>

And the output looks like this:

array(2) {
  [0]=>
  array(8) {
    ["id"]=>
    string(1) "1"
    [0]=>
    string(1) "1"
    ["id_cli"]=>
    string(1) "1"
    [1]=>
    string(1) "1"
    ["user"]=>
    string(12) "david.santos"
    [2]=>
    string(12) "david.santos"
    ["senha"]=>
    string(60) "I82A1G"
    [3]=>
    string(60) "I82A1G"
  }
  [1]=>
  array(8) {
    ["id"]=>
    string(1) "2"
    [0]=>
    string(1) "2"
    ["id_cli"]=>
    string(1) "2"
    [1]=>
    string(1) "2"
    ["user"]=>
    string(12) "joao.batista"
    [2]=>
    string(12) "joao.batista"
    ["senha"]=>
    string(6) "senha"
    [3]=>
    string(6) "senha"
  }
}

Doubt is because the data is duplicate? I know that if I use "fetch (PDO :: FETCH_ASSOC)" the problem will be solved but I would like to understand why this is happening

    
asked by anonymous 11.06.2017 / 04:14

1 answer

1

You are only showing the value of the items by the Key and Index of each, it is not duplicated, or you use the keys or indexes to access the values

    
11.06.2017 / 06:25