Gdn_DataSet::value PHP Method

value() public method

Advances to the next row and returns the value from a column.
public value ( string $ColumnName, string $DefaultValue = null ) : mixed
$ColumnName string The name of the column to get the value from.
$DefaultValue string The value to return if there is no data.
return mixed The value from the column or $DefaultValue.
    public function value($ColumnName, $DefaultValue = null)
    {
        if ($Row = $this->nextRow()) {
            if (is_array($ColumnName)) {
                $Result = array();
                foreach ($ColumnName as $Name => $Default) {
                    if (is_object($Row) && property_exists($Row, $Name)) {
                        return $Row->{$Name};
                    } elseif (is_array($Row) && array_key_exists($Name, $Row)) {
                        return $Row[$Name];
                    } else {
                        $Result[] = $Default;
                    }
                }
                return $Result;
            } else {
                if (is_object($Row) && property_exists($Row, $ColumnName)) {
                    return $Row->{$ColumnName};
                } elseif (is_array($Row) && array_key_exists($ColumnName, $Row)) {
                    return $Row[$ColumnName];
                }
            }
        }
        if (is_array($ColumnName)) {
            return array_values($ColumnName);
        }
        return $DefaultValue;
    }