Getting values from the array

-1

I have the following array:

array(2) {
  [0]=>
  array(2) {
    ["username"]=>
    string(6) "User01"
    ["quant"]=>
    string(1) "6"
  }
  [1]=>
  array(2) {
    ["username"]=>
    string(5) "Teste"
    ["quant"]=>
    string(1) "3"
  }
 [2]=>
  array(2) {
    ["username"]=>
    string(5) "xxXxx"
    ["quant"]=>
    string(1) "5"
  }
}

How do I get all the "username" fields and list, "User01, Test, xxXxx"

I found a function that lists only the array id:

  $resultado[0][username];
  echo $resultado;
  User01

I just printed the value set la [0], but I want it to print all the username.

Here is the complete code, but only the last regit.

$sql = 'SELECT username, COUNT(*) AS quant FROM acessos WHERE hora > :hora GROUP BY username';
$statement = $pdo->prepare($sql);
$statement->bindValue(":hora", date('H:i:s', strtotime('-1 minutes')));
$statement->execute();
$resultado = $statement->fetchAll(PDO::FETCH_ASSOC);

//var_dump($resultado);
foreach($resultado as $item){
    $dados = $item["username"];
}
 echo "-> " . $dados;
 -> xxXxx
    
asked by anonymous 04.09.2017 / 18:40

1 answer

4

loop to scroll through all the items in the outermost array.

foreach($array as $item){
    echo $item["username"] . PHP_EOL;
}

See working on repl.it .

    
04.09.2017 / 18:42