Gdn_SQLDriver::_whereIn PHP Method

_whereIn() public method

Adds to the $this->_WhereIns collection. Used to generate a "where field in (1,2,3)" query. Called by $this->WhereIn(), $this->OrWhereIn(), $this->WhereNotIn(), and $this->OrWhereNotIn().
public _whereIn ( string $Field, array $Values, string $Op = 'in', string $Escape = true ) : Gdn_SQLDriver
$Field string The field to search in for $Values.
$Values array An array of values to look for in $Field.
$Op string Either 'in' or 'not in' for the respective operation.
$Escape string Whether or not to escape the items in $Values. clause.
return Gdn_SQLDriver $this
    public function _whereIn($Field, $Values, $Op = 'in', $Escape = true)
    {
        if (is_null($Field) || !is_array($Values)) {
            return;
        }
        $FieldExpr = $this->_parseExpr($Field);
        // Build up the in clause.
        $In = array();
        foreach ($Values as $Value) {
            if ($Escape) {
                $ValueExpr = $this->Database->connection()->quote($Value);
            } else {
                $ValueExpr = (string) $Value;
            }
            if (strlen($ValueExpr) > 0) {
                $In[] = $ValueExpr;
            }
        }
        if (count($In) > 0) {
            $InExpr = '(' . implode(', ', $In) . ')';
        } else {
            $InExpr = '(null)';
        }
        // Set the final expression.
        $Expr = $FieldExpr . ' ' . $Op . ' ' . $InExpr;
        $this->_where($Expr);
        return $this;
    }