Answer the question
In order to leave comments, you need to log in
How to get array: key from first column, value from second?
Good afternoon! When executing a query like this:
$stmt->prepare("SELECT column_1, column_2 FROM table");
$stmt->execute();
$result_array = $stmt->fetchAll(PDO::FETCH_COLUMN | PDO::FETCH_GROUP);
array {
[column_1_value]=>
array(1) {
[0]=>
string(8) "column_2_value"
}
[column_1_value]=>
array(1) {
[0]=>
string(8) "column_2_value"
}
...
}
array {
[column_1_value]=> string(8) "column_2_value"
[column_1_value]=> string(8) "column_2_value"
...
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question