src/Categories/Getters.php
public static function getRectangularDimensions(array $array)
    {
        $return = -1;
        $allArrays = array_map('is_array', $array);
        // all elements are arrays, iterate through them and call the static function recursively
        if (self::allElementsEqual($allArrays, true)) {
            $elementsPerArray = array();
            foreach ($array as $row) {
                $noElements = self::getRectangularDimensions($row);
                if ($noElements == -1) {
                    return $noElements;
                }
                $elementsPerArray[] = $noElements;
            }
            if (!self::allElementsEqual($elementsPerArray)) {
                return -1;
            } else {
                $return   = reset($elementsPerArray);
                $return[] = count($elementsPerArray);
            }
        } // none of the elements are arrays, return number of elements of the "bottom" array
        elseif (self::allElementsEqual($allArrays, false)) {
            $return = array(0 => count($array));
        }

        return $return;
    }
public static function getRectangularDimensions(array $array)
    {
        $return = -1;
        $allArrays = array_map('is_array', $array);
        // all elements are arrays, iterate through them and call the static function recursively
        if (self::allElementsEqual($allArrays, true)) {
            $elementsPerArray = array();
            foreach ($array as $row) {
                $noElements = self::getRectangularDimensions($row);
                if ($noElements == -1) {
                    return $noElements;
                }
                $elementsPerArray[] = $noElements;
            }
            if (!self::allElementsEqual($elementsPerArray)) {
                return -1;
            } else {
                $return   = reset($elementsPerArray);
                $return[] = count($elementsPerArray);
            }
        } // none of the elements are arrays, return number of elements of the "bottom" array
        elseif (self::allElementsEqual($allArrays, false)) {
            $return = array(0 => count($array));
        }

        return $return;
    }
public static function getRectangularDimensions ( array $ array ) { $ return = - 1 ; $ allArrays = array_map ( 'is_array' , $ array ) ; // all elements are arrays, iterate through them and call the static function recursively if ( self :: allElementsEqual ( $ allArrays , true ) ) { $ elementsPerArray = array ( ) ; foreach ( $ array as $ row ) { $ noElements = self :: getRectangularDimensions ( $ row ) ; if ( $ noElements == - 1 ) { return $ noElements ; } $ elementsPerArray [ ] = $ noElements ; } if ( ! self :: allElementsEqual ( $ elementsPerArray ) ) { return - 1 ; } else { $ return = reset ( $ elementsPerArray ) ; $ return [ ] = count ( $ elementsPerArray ) ; } } // none of the elements are arrays, return number of elements of the "bottom" array elseif ( self :: allElementsEqual ( $ allArrays , false ) ) { $ return = array ( 0 => count ( $ array ) ) ; } return $ return ; }
Checks if an array is rectangular array and returns dimensions or -1 if it's not rectangular

@param array $array

@return int|array
Checks if an array is rectangular array and returns dimensions or - 1 if it s not rectangular