| @@ 797-824 (lines=28) @@ | ||
| 794 | * |
|
| 795 | * @return array A grouped array of scalar values or arrays |
|
| 796 | */ |
|
| 797 | public function fetchGroups(string $group, string $column = null): array |
|
| 798 | { |
|
| 799 | // init |
|
| 800 | $groups = []; |
|
| 801 | $pos = $this->current_row; |
|
| 802 | ||
| 803 | foreach ($this as $row) { |
|
| 804 | ||
| 805 | if (!\array_key_exists($group, $row)) { |
|
| 806 | continue; |
|
| 807 | } |
|
| 808 | ||
| 809 | if (null !== $column) { |
|
| 810 | ||
| 811 | if (!\array_key_exists($column, $row)) { |
|
| 812 | continue; |
|
| 813 | } |
|
| 814 | ||
| 815 | $groups[$row[$group]][] = $row[$column]; |
|
| 816 | } else { |
|
| 817 | $groups[$row[$group]][] = $row; |
|
| 818 | } |
|
| 819 | } |
|
| 820 | ||
| 821 | $this->rewind($pos); |
|
| 822 | ||
| 823 | return $groups; |
|
| 824 | } |
|
| 825 | ||
| 826 | /** |
|
| 827 | * Fetch as object. |
|
| @@ 897-924 (lines=28) @@ | ||
| 894 | * |
|
| 895 | * @return array An array of key-value pairs |
|
| 896 | */ |
|
| 897 | public function fetchPairs(string $key, string $column = null): array |
|
| 898 | { |
|
| 899 | // init |
|
| 900 | $pairs = []; |
|
| 901 | $pos = $this->current_row; |
|
| 902 | ||
| 903 | foreach ($this as $row) { |
|
| 904 | ||
| 905 | if (!\array_key_exists($key, $row)) { |
|
| 906 | continue; |
|
| 907 | } |
|
| 908 | ||
| 909 | if (null !== $column) { |
|
| 910 | ||
| 911 | if (!\array_key_exists($column, $row)) { |
|
| 912 | continue; |
|
| 913 | } |
|
| 914 | ||
| 915 | $pairs[$row[$key]] = $row[$column]; |
|
| 916 | } else { |
|
| 917 | $pairs[$row[$key]] = $row; |
|
| 918 | } |
|
| 919 | } |
|
| 920 | ||
| 921 | $this->rewind($pos); |
|
| 922 | ||
| 923 | return $pairs; |
|
| 924 | } |
|
| 925 | ||
| 926 | /** |
|
| 927 | * Returns all rows at once, transposed as an array of arrays. Instead of |
|