| @@ 833-860 (lines=28) @@ | ||
| 830 | * |
|
| 831 | * @return array A grouped array of scalar values or arrays |
|
| 832 | */ |
|
| 833 | public function fetchGroups(string $group, string $column = null): array |
|
| 834 | { |
|
| 835 | // init |
|
| 836 | $groups = []; |
|
| 837 | $pos = $this->current_row; |
|
| 838 | ||
| 839 | foreach ($this as $row) { |
|
| 840 | ||
| 841 | if (!\array_key_exists($group, $row)) { |
|
| 842 | continue; |
|
| 843 | } |
|
| 844 | ||
| 845 | if (null !== $column) { |
|
| 846 | ||
| 847 | if (!\array_key_exists($column, $row)) { |
|
| 848 | continue; |
|
| 849 | } |
|
| 850 | ||
| 851 | $groups[$row[$group]][] = $row[$column]; |
|
| 852 | } else { |
|
| 853 | $groups[$row[$group]][] = $row; |
|
| 854 | } |
|
| 855 | } |
|
| 856 | ||
| 857 | $this->rewind($pos); |
|
| 858 | ||
| 859 | return $groups; |
|
| 860 | } |
|
| 861 | ||
| 862 | /** |
|
| 863 | * Fetch as object. |
|
| @@ 932-959 (lines=28) @@ | ||
| 929 | * |
|
| 930 | * @return array An array of key-value pairs |
|
| 931 | */ |
|
| 932 | public function fetchPairs(string $key, string $column = null): array |
|
| 933 | { |
|
| 934 | // init |
|
| 935 | $pairs = []; |
|
| 936 | $pos = $this->current_row; |
|
| 937 | ||
| 938 | foreach ($this as $row) { |
|
| 939 | ||
| 940 | if (!\array_key_exists($key, $row)) { |
|
| 941 | continue; |
|
| 942 | } |
|
| 943 | ||
| 944 | if (null !== $column) { |
|
| 945 | ||
| 946 | if (!\array_key_exists($column, $row)) { |
|
| 947 | continue; |
|
| 948 | } |
|
| 949 | ||
| 950 | $pairs[$row[$key]] = $row[$column]; |
|
| 951 | } else { |
|
| 952 | $pairs[$row[$key]] = $row; |
|
| 953 | } |
|
| 954 | } |
|
| 955 | ||
| 956 | $this->rewind($pos); |
|
| 957 | ||
| 958 | return $pairs; |
|
| 959 | } |
|
| 960 | ||
| 961 | /** |
|
| 962 | * Returns all rows at once, transposed as an array of arrays. Instead of |
|