function kintParser::_isArrayTabular

1 call to kintParser::_isArrayTabular()
kintParser::_parse_array in kint/kint/inc/kintParser.class.php

File

kint/kint/inc/kintParser.class.php, line 170

Class

kintParser

Code

private static function _isArrayTabular(array $variable) {
    if (Kint::enabled() !== Kint::MODE_RICH) {
        return false;
    }
    $arrayKeys = array();
    $keys = null;
    $closeEnough = false;
    foreach ($variable as $row) {
        if (!is_array($row) || empty($row)) {
            return false;
        }
        foreach ($row as $col) {
            if (!empty($col) && !is_scalar($col)) {
                return false;
            }
            // todo add tabular "tolerance"
        }
        if (isset($keys) && !$closeEnough) {
            
            # let's just see if the first two rows have same keys, that's faster and has the
            
            # positive side effect of easily spotting missing keys in later rows
            if ($keys !== array_keys($row)) {
                return false;
            }
            $closeEnough = true;
        }
        else {
            $keys = array_keys($row);
        }
        $arrayKeys = array_unique(array_merge($arrayKeys, $keys));
    }
    return $arrayKeys;
}