Return list of elements for use with SQL's IN clause

@param array  $arr  Input array
@param string $type Type of data (integer, bool, ident)

@return string Comma-separated list of quoted values for use in query
433856
public function array2list($arr, $type = null)
    {
        if (!is_array($arr)) {
            return $this->quote($arr, $type);
        }

        foreach ($arr as $idx => $item) {
            $arr[$idx] = $this->quote($item, $type);
        }

        return implode(',', $arr);
    }
399705
public function to($type = 'array')
	{
		$rows = [];

		if ($this->rows && $this->count())
		{
			foreach ($this->rows as $row)
			{
				$method = 'to' . ucfirst($type);
				$rows[] = $row->$method();
			}
		}

		return $rows;
	}
57323
function _query($sql,$inputarr=false)
	{
		if (is_array($sql)) {
			$stmt = $sql[1];
		} else {
			$stmt = $this->_connectionID->prepare($sql);
		}
		#adodb_backtrace();
		#var_dump($this->_bindInputArray);
		if ($stmt) {
			$this->_driver->debug = $this->debug;
			if ($inputarr) {
				$ok = $stmt->execute($inputarr);
			}
			else {
				$ok = $stmt->execute();
			}
		}


		$this->_errormsg = false;
		$this->_errorno = false;

		if ($ok) {
			$this->_stmt = $stmt;
			return $stmt;
		}

		if ($stmt) {

			$arr = $stmt->errorinfo();
			if ((integer)$arr[1]) {
				$this->_errormsg = $arr[2];
				$this->_errorno = $arr[1];
			}

		} else {
			$this->_errormsg = false;
			$this->_errorno = false;
		}
		return false;
	}
985156
public function fromArray($arr)
    {
        $class = $this->getFullyQualifiedModel();
        foreach ($arr as $element) {
            /** @var $obj ActiveRecordInterface */
            $obj = new $class();
            $obj->fromArray($element);
            $this->append($obj);
        }
    }
927921
public function fetchAll($type = self::FETCH_TYPE_NUM)
    {
        if ($this->_allFetched) {
            return $this->buffer;
        }
        $results = $this->statement->fetchAll($type);
        if ($results !== false) {
            $this->buffer = array_merge($this->buffer, $results);
        }
        $this->_allFetched = true;
        $this->statement->closeCursor();

        return $this->buffer;
    }
522978
public static function array_type(&$arr=null) {
		if (! \is_array($arr) || ! \count($arr)) {
			return false;
		}

		$keys = \array_keys($arr);
		if (\range(0, \count($keys) - 1) === $keys) {
			return 'sequential';
		}
		elseif (\count($keys) === \count(\array_filter($keys, 'is_numeric'))) {
			return 'indexed';
		}
		else {
			return 'associative';
		}
	}
1269918
private static function array_filter($arr, $values, $inverse = false)
    {
        if (!is_array($values)) {
            $values = explode(',', $values);
        }

        $result = array();
        $keep   = array_flip((array)$values);

        foreach ($arr as $key => $val) {
            if ($inverse != isset($keep[strtolower($val)])) {
                $result[$key] = $val;
            }
        }

        return $result;
    }
728343
static function ArrayToQueryString($arr)
	{
		$qs = $arr;

		if (is_array($arr))
		{
			// convert the data array into a url querystring
			$qs = "";
			$delim = "";
			foreach (array_keys($arr) as $key)
			{
				$qs .= $delim . $key ."=" . $arr[$key];
				$delim = "&";
			}
		}

		return $qs;
	}
796829
private function doInsert(array $data, string $type)
    {
        // Insert single item

        if (\is_array(current($data)) === false) {
            $queryObject = $this->getQuery($type, $data);

            $this->connection->setLastQuery($queryObject);

            $this->fireEvents(EventHandler::EVENT_BEFORE_INSERT, $queryObject);
            /**
             * @var $result        \PDOStatement
             * @var $executionTime float
             */
            [$result, $executionTime] = $this->statement($queryObject->getSql(), $queryObject->getBindings());

            $insertId = $result->rowCount() === 1 ? $this->pdo()->lastInsertId() : null;
            $this->fireEvents(EventHandler::EVENT_AFTER_INSERT, $queryObject, [
                'insert_id'      => $insertId,
                'execution_time' => $executionTime,
            ]);

            return $insertId;
        }

        $insertIds = [];

        // If the current batch insert is not in a transaction, we create one...

        if ($this->pdo()->inTransaction() === false) {

            $this->transaction(function (Transaction $transaction) use (&$insertIds, $data, $type) {
                foreach ($data as $subData) {
                    $insertIds[] = $transaction->doInsert($subData, $type);
                }
            });

            return $insertIds;
        }

        // Otherwise insert one by one...
        foreach ($data as $subData) {
            $insertIds[] = $this->doInsert($subData, $type);
        }

        return $insertIds;
    }
402582
protected function to2DArray($arr)
    {
        if (empty($arr) || !is_array($arr)) {
            return [];
        }
        if (count($arr) == count($arr, COUNT_RECURSIVE)) {
            return [$arr];
        }
        return $arr;
    }
236398
function (arr) {
        var result = true;
        arr.forEach(function (elem) {
            if (!(typeof elem === 'string' || typeof elem === 'number')) {
                result = false;
            }
        });

        return result;
    }
43581
public static function createPrepareFields(array &$data, string $type = 'insert') : string
    {
        $string = '';
        $dataTmp = [];
        switch ($type) {
            case 'insert':
                if (isset($data[0]) && \is_array($data[0])) {
                    foreach ($data as $index => &$value) {
                        $tmp = '';
                        foreach ($value as $k => &$v) {
                            $tmp .= ":$k$index,";
                            $dataTmp[$k . $index] = $v;
                        }

                        unset($v);

                        $string .= '(' . trim($tmp, ',') . '),';
                    }

                    unset($value);

                    $string = trim($string, ',');
                    $data = $dataTmp;
                    unset($dataTmp, $tmp, $value);
                } else {
                    $string = '(:' . implode(',:', array_keys($data)) . ')';
                }

                break;

            case 'update':
                $dataTmp = array_map(static function($item) {
                    return "$item = :$item";
                }, array_keys($data));

                $string = implode(', ', $dataTmp);

                break;
        }

        return $string;
    }
145070
public function getConditionSql(array $sql, array $where, string $conditionType): array
    {
        if (empty($where)) {
            return $sql;
        }
        foreach ($where as $index => $item) {
            if ($item instanceof RawExp) {
                if ($index == 0) {
                    $sql[] = $conditionType . ' ' . $item->getValue();
                    continue;
                }
                $sql[] = $item->getValue();
                continue;
            }
            [$type, $conditions] = $item;
            if (!$index) {
                $whereType = $conditionType;
            } else {
                $whereType = strtoupper($type);
            }
            if ($conditions[0] instanceof RawExp) {
                $sql[] = $whereType . ' ' . $conditions[0]->getValue();
                continue;
            }
            [$leftField, $operator, $rightField] = $conditions;
            $leftField = $this->quoter->quoteName($leftField);
            [$rightField, $operator] = $this->getRightFieldValue($rightField, $operator);

            $sql[] = sprintf('%s %s %s %s', $whereType, $leftField, $operator, $rightField);
        }

        return $sql;
    }
456644
public function results($type = 'array')
    {
        switch ($type) {
            case 'array':
                // return array data
                return $this->results;
                break;
            case 'xml':
                //send the xml header to the browser
                header('Content-Type:text/xml');
                // return xml content
                return $this->helper()->arrayToXml($this->results);
                break;
            case 'json':
                // set header as json
                header('Content-type: application/json; charset="utf-8"');
                // return json encoded data
                return json_encode($this->results);
                break;
        }
    }
1347854
public function fetch($array, $type = 'object')
    {
        $data = [];
        //
        foreach ($array as $row) {
            //
            if ($type == 'object') {
                $rw = new Row();
                //
                foreach ($row as $index => $column) {
                    if (!is_int($index)) {
                        $rw->$index = $column;
                    }
                }
            } elseif ($type == 'array') {
                $rw = [];
                //
                foreach ($row as $index => $column) {
                    if (!is_int($index)) {
                        $rw[$index] = $column;
                    }
                }
            }

            //
            $data[] = $rw;
        }
        //
        return $data;
    }
1036362
private function buildQuery($type = 'select')
	{
		$pieces = array();

		// Loop through query elements
		foreach ($this->$type as $piece)
		{
			// If we have one of these elements, get its string value
			if ($element = $this->syntax->build($piece))
			{
				$pieces[] = $element;
			}
		}

		return implode("\n", $pieces);
	}
875695
public static @NotNull SqlArray of(@NotNull String type, @NotNull Object[] values) {
        return of(type, asList(values));
    }