Skip to content

Commit 7f8b8c3

Browse files
committed
fetchPairs() supports floats in keys
1 parent 2ee4dd2 commit 7f8b8c3

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/Database/Helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public static function toPairs(array $rows, $key = null, $value = null): array
262262
}
263263
} else {
264264
foreach ($rows as $row) {
265-
$return[is_object($row[$key]) ? (string) $row[$key] : $row[$key]] = ($value === null ? $row : $row[$value]);
265+
$return[(string) $row[$key]] = ($value === null ? $row : $row[$value]);
266266
}
267267
}
268268

tests/Database/ResultSet.fetchPairs().phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,9 @@ Assert::same([
128128
'2002-02-02 00:00:00' => 'David Grudl',
129129
'2002-02-20 00:00:00' => 'Jakub Vrana',
130130
], $pairs);
131+
132+
133+
$pairs = $context->query('SELECT 1.5 AS k, 1 AS v')->fetchPairs();
134+
Assert::equal([
135+
'1.5' => 1,
136+
], $pairs);

0 commit comments

Comments
 (0)