| @@ 708-735 (lines=28) @@ | ||
| 705 | * |
|
| 706 | * @return array A grouped array of scalar values or arrays |
|
| 707 | */ |
|
| 708 | public function fetchGroups(string $group, string $column = null): array |
|
| 709 | { |
|
| 710 | // init |
|
| 711 | $groups = []; |
|
| 712 | $pos = $this->current_row; |
|
| 713 | ||
| 714 | foreach ($this as $row) { |
|
| 715 | ||
| 716 | if (!\array_key_exists($group, $row)) { |
|
| 717 | continue; |
|
| 718 | } |
|
| 719 | ||
| 720 | if (null !== $column) { |
|
| 721 | ||
| 722 | if (!\array_key_exists($column, $row)) { |
|
| 723 | continue; |
|
| 724 | } |
|
| 725 | ||
| 726 | $groups[$row[$group]][] = $row[$column]; |
|
| 727 | } else { |
|
| 728 | $groups[$row[$group]][] = $row; |
|
| 729 | } |
|
| 730 | } |
|
| 731 | ||
| 732 | $this->rewind($pos); |
|
| 733 | ||
| 734 | return $groups; |
|
| 735 | } |
|
| 736 | ||
| 737 | /** |
|
| 738 | * Fetch as object. |
|
| @@ 801-828 (lines=28) @@ | ||
| 798 | * |
|
| 799 | * @return array An array of key-value pairs |
|
| 800 | */ |
|
| 801 | public function fetchPairs(string $key, string $column = null): array |
|
| 802 | { |
|
| 803 | // init |
|
| 804 | $pairs = []; |
|
| 805 | $pos = $this->current_row; |
|
| 806 | ||
| 807 | foreach ($this as $row) { |
|
| 808 | ||
| 809 | if (!\array_key_exists($key, $row)) { |
|
| 810 | continue; |
|
| 811 | } |
|
| 812 | ||
| 813 | if (null !== $column) { |
|
| 814 | ||
| 815 | if (!\array_key_exists($column, $row)) { |
|
| 816 | continue; |
|
| 817 | } |
|
| 818 | ||
| 819 | $pairs[$row[$key]] = $row[$column]; |
|
| 820 | } else { |
|
| 821 | $pairs[$row[$key]] = $row; |
|
| 822 | } |
|
| 823 | } |
|
| 824 | ||
| 825 | $this->rewind($pos); |
|
| 826 | ||
| 827 | return $pairs; |
|
| 828 | } |
|
| 829 | ||
| 830 | /** |
|
| 831 | * Returns all rows at once, transposed as an array of arrays. Instead of |
|