Overview
Comment:Make array_transpose behave nicely with missing rows in some columns
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: 235afc802ef80dd4df2a944d2505b06c0a0487d4
User & Date: bohwaz on 2020-12-05 10:44:03
Other Links: branch diff | manifest | tags
Context
2020-12-05
10:44
Fix clickable row in tables that are not lists check-in: 5467e536da user: bohwaz tags: dev, 1.0.0-rc6
10:44
Make array_transpose behave nicely with missing rows in some columns check-in: 235afc802e user: bohwaz tags: dev
10:22
Rename .htaccess check-in: e034f24906 user: bohwaz tags: dev, 1.0.0-rc6
Changes

Modified src/include/lib/Garradin/Utils.php from [2099105858] to [c164f7f4a8].

750
751
752
753
754
755
756
757
758
759
760
761
762
763


764

765

766
767
768
769
770
771
772
                throw new \InvalidArgumentException('Unknown icon shape: ' . $shape);
        }
    }

    static public function array_transpose(array $array): array
    {
        $out = [];
        $count = null;

        foreach ($array as $column => $rows) {
            if (null !== $count && count($rows) != $count) {
                throw new \LogicException('Array is inconsistent');
            }



            $count = count($rows);



            foreach ($rows as $k => $v) {
                if (!isset($out[$k])) {
                    $out[$k] = [];
                }

                $out[$k][$column] = $v;
            }







|

|
|
<
|

>
>
|
>
|
>







750
751
752
753
754
755
756
757
758
759
760

761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
                throw new \InvalidArgumentException('Unknown icon shape: ' . $shape);
        }
    }

    static public function array_transpose(array $array): array
    {
        $out = [];
        $max = 0;

        foreach ($array as $rows) {
            $max = max($max, count($rows));

        }

        foreach ($array as $column => $rows) {
            // Match number of rows of largest sub-array, in case there is a missing row in a column
            if ($max != count($rows)) {
                $rows = array_merge($rows, array_fill(0, $max - count($rows), null));
            }

            foreach ($rows as $k => $v) {
                if (!isset($out[$k])) {
                    $out[$k] = [];
                }

                $out[$k][$column] = $v;
            }