public function validate(): bool
    {
        // The number of columns
        $numberOfColumns = null;

        // Reset the errors
        $this->errors = [];

        // Check that there are rows in the data
        if (0 >= count($this->data)) {
            $message        = 'There are no rows in the table';
            $this->errors[] = $message;

            return false;
        }

        // Check that all rows have the same number of columns
        foreach ($this->data as $row) {
            $found = count($row);

            if (null === $numberOfColumns) {
                $numberOfColumns = $found;
            }

            if ($numberOfColumns !== $found) {
                $message = sprintf(
                    'The number of columns mismatches. First row has %s columns while column %s has %s.',
                    $numberOfColumns,
                    key($row),
                    $found
                );
                $this->errors[] = $message;
            }
        }

        return 0 < count($this->errors) ? false : true;
    }
public function validate(): bool
    {
        // The number of columns
        $numberOfColumns = null;

        // Reset the errors
        $this->errors = [];

        // Check that there are rows in the data
        if (0 >= count($this->data)) {
            $message        = 'There are no rows in the table';
            $this->errors[] = $message;

            return false;
        }

        // Check that all rows have the same number of columns
        foreach ($this->data as $row) {
            $found = count($row);

            if (null === $numberOfColumns) {
                $numberOfColumns = $found;
            }

            if ($numberOfColumns !== $found) {
                $message = sprintf(
                    'The number of columns mismatches. First row has %s columns while column %s has %s.',
                    $numberOfColumns,
                    key($row),
                    $found
                );
                $this->errors[] = $message;
            }
        }

        return 0 < count($this->errors) ? false : true;
    }
public function validate ( ) : bool { // The number of columns $ numberOfColumns = null ; // Reset the errors $ this -> errors = [ ] ; // Check that there are rows in the data if ( 0 >= count ( $ this -> data ) ) { $ message = 'There are no rows in the table' ; $ this -> errors [ ] = $ message ; return false ; } // Check that all rows have the same number of columns foreach ( $ this -> data as $ row ) { $ found = count ( $ row ) ; if ( null === $ numberOfColumns ) { $ numberOfColumns = $ found ; } if ( $ numberOfColumns !== $ found ) { $ message = sprintf ( 'The number of columns mismatches. First row has %s columns while column %s has %s.' , $ numberOfColumns , key ( $ row ) , $ found ) ; $ this -> errors [ ] = $ message ; } } return 0 < count ( $ this -> errors ) ? false : true ; }
Validates the given array to check all the rows have the same number of columns.

Returns false if the validation fails and calling the getErrors() method it is possible to know
which are these errors.

@return bool False if the validation fails, true if all succeeds
Validates the given array to check all the rows have the same number of columns .