$sql = "SELECT name FROM people WHERE id = '$id'";
$array = array();
$q = $pdo->prepare($sql);
$q->execute();
foreach ($pdo->query($sql) as $row) {
$array[] = $row;
}
My result is:
array(4) {
[0]=>
array(2) {
["name"]=>
string(4) "fred"
[0]=>
string(4) "fred"
}
[1]=>
array(2) {
["name"]=>
string(3) "sam"
[0]=>
string(3) "sam"
}
[2]=>
array(2) {
["name"]=>
string(4) "alan"
[0]=>
string(4) "alan"
}
[3]=>
array(2) {
["name"]=>
string(63) "john"
[0]=>
string(63) "john"
}
}
But I would need:
Array
(
[fred] => fred
[sam] => sam
[alan] => alan
[john] => john
)
I tried for example:
foreach ($pdo->query($sql) as $key => $row) {..
and also
foreach ($pdo->query($sql) as $row) {
$array[] = $row;
$row = array_combine(array_values($row), array_values($row));
}
but I always get the same result...