| @@ 891-916 (lines=26) @@ | ||
| 888 | * @return array |
|
| 889 | * <p>A grouped array of scalar values or arrays.</p> |
|
| 890 | */ |
|
| 891 | public function &fetchGroups(string $group, string $column = null): array |
|
| 892 | { |
|
| 893 | // init |
|
| 894 | $groups = []; |
|
| 895 | $pos = $this->current_row; |
|
| 896 | ||
| 897 | foreach ($this->fetchAllArrayyYield() as $row) { |
|
| 898 | if (!\array_key_exists($group, $row)) { |
|
| 899 | continue; |
|
| 900 | } |
|
| 901 | ||
| 902 | if ($column !== null) { |
|
| 903 | if (!\array_key_exists($column, $row)) { |
|
| 904 | continue; |
|
| 905 | } |
|
| 906 | ||
| 907 | $groups[$row[$group]][] = $row[$column]; |
|
| 908 | } else { |
|
| 909 | $groups[$row[$group]][] = $row; |
|
| 910 | } |
|
| 911 | } |
|
| 912 | ||
| 913 | $this->rewind($pos); |
|
| 914 | ||
| 915 | return $groups; |
|
| 916 | } |
|
| 917 | ||
| 918 | /** |
|
| 919 | * Fetch as object. |
|
| @@ 995-1020 (lines=26) @@ | ||
| 992 | * @return array |
|
| 993 | * <p>An array of key-value pairs.</p> |
|
| 994 | */ |
|
| 995 | public function fetchPairs(string $key, string $column = null): array |
|
| 996 | { |
|
| 997 | // init |
|
| 998 | $pairs = []; |
|
| 999 | $pos = $this->current_row; |
|
| 1000 | ||
| 1001 | foreach ($this->fetchAllArrayyYield() as $row) { |
|
| 1002 | if (!\array_key_exists($key, $row)) { |
|
| 1003 | continue; |
|
| 1004 | } |
|
| 1005 | ||
| 1006 | if ($column !== null) { |
|
| 1007 | if (!\array_key_exists($column, $row)) { |
|
| 1008 | continue; |
|
| 1009 | } |
|
| 1010 | ||
| 1011 | $pairs[$row[$key]] = $row[$column]; |
|
| 1012 | } else { |
|
| 1013 | $pairs[$row[$key]] = $row; |
|
| 1014 | } |
|
| 1015 | } |
|
| 1016 | ||
| 1017 | $this->rewind($pos); |
|
| 1018 | ||
| 1019 | return $pairs; |
|
| 1020 | } |
|
| 1021 | ||
| 1022 | /** |
|
| 1023 | * Returns all rows at once, transposed as an array of arrays. Instead of |
|