public static function countConsistentColumns(array $matrix, array $ignoreValues = [], $emptyIsConsistent = false)
    {
        $consistentCount = 0;
        
        if (!self::isValidMatrix($matrix)) {
            return $consistentCount;
        }
        
        for ($i = 0; $i < count($matrix[0]); $i++) {
            $column = array_column($matrix, $i);
            if (count($column) !== count($matrix)) {
                // Malformed matrix.
                return false;
            }
            
            $column = array_unique($column);
            
            foreach ($ignoreValues as $ignoreVal) {
                if (($search = array_search($ignoreVal, $column, true)) !== false) {
                    unset($column[$search]);
                }
            }
            
            if (count($column) === 1) {
                $consistentCount++;
            } elseif (count($column) === 0 && $emptyIsConsistent) {
                $consistentCount++;
            }
        }
        
        return $consistentCount;
    }
public static function countConsistentColumns(array $matrix, array $ignoreValues = [], $emptyIsConsistent = false)
    {
        $consistentCount = 0;
        
        if (!self::isValidMatrix($matrix)) {
            return $consistentCount;
        }
        
        for ($i = 0; $i < count($matrix[0]); $i++) {
            $column = array_column($matrix, $i);
            if (count($column) !== count($matrix)) {
                // Malformed matrix.
                return false;
            }
            
            $column = array_unique($column);
            
            foreach ($ignoreValues as $ignoreVal) {
                if (($search = array_search($ignoreVal, $column, true)) !== false) {
                    unset($column[$search]);
                }
            }
            
            if (count($column) === 1) {
                $consistentCount++;
            } elseif (count($column) === 0 && $emptyIsConsistent) {
                $consistentCount++;
            }
        }
        
        return $consistentCount;
    }
public static function countConsistentColumns ( array $ matrix , array $ ignoreValues = [ ] , $ emptyIsConsistent = false ) { $ consistentCount = 0 ; if ( ! self :: isValidMatrix ( $ matrix ) ) { return $ consistentCount ; } for ( $ i = 0 ; $ i < count ( $ matrix [ 0 ] ) ; $ i ++ ) { $ column = array_column ( $ matrix , $ i ) ; if ( count ( $ column ) !== count ( $ matrix ) ) { // Malformed matrix. return false ; } $ column = array_unique ( $ column ) ; foreach ( $ ignoreValues as $ ignoreVal ) { if ( ( $ search = array_search ( $ ignoreVal , $ column , true ) ) !== false ) { unset ( $ column [ $ search ] ) ; } } if ( count ( $ column ) === 1 ) { $ consistentCount ++ ; } elseif ( count ( $ column ) === 0 && $ emptyIsConsistent ) { $ consistentCount ++ ; } } return $ consistentCount ; }
Count the Amount of Consistent Columns in Matrix

This method aims at counting the number of columns in a $matrix containing strictly similar values.

@param array $matrix An array containing exclusively arrays.
@param array $ignoreValues An array of values to be ignored while comparing values within columns.
@param array $emptyIsConsistent (optional) Consider empty columns (after ignoring values) as consistent.
@return mixed The amount of consistent columns in $matrix or false if $matrix is not a well formed matrix.
Count the Amount of Consistent Columns in Matrix