Think\Db\Query::value PHP Method

value() public method

得到某个字段的值
public value ( string $field, mixed $default = null ) : mixed
$field string 字段名
$default mixed 默认值
return mixed
    public function value($field, $default = null)
    {
        $result = false;
        if (!empty($this->options['cache'])) {
            // 判断查询缓存
            $cache = $this->options['cache'];
            if (empty($this->options['table'])) {
                $this->options['table'] = $this->getTable();
            }
            $key = is_string($cache['key']) ? $cache['key'] : md5($field . serialize($this->options));
            $result = Cache::get($key);
        }
        if (false === $result) {
            if (isset($this->options['field'])) {
                unset($this->options['field']);
            }
            $pdo = $this->field($field)->fetchPdo(true)->find();
            if (is_string($pdo)) {
                // 返回SQL语句
                return $pdo;
            }
            $result = $pdo->fetchColumn();
            if (isset($cache)) {
                // 缓存数据
                if (isset($cache['tag'])) {
                    Cache::tag($cache['tag'])->set($key, $result, $cache['expire']);
                } else {
                    Cache::set($key, $result, $cache['expire']);
                }
            }
        } else {
            // 清空查询条件
            $this->options = [];
        }
        return false !== $result ? $result : $default;
    }