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