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