Class: TableArray

Declaration class TableArray extends \ArrayIterator implements \JsonSerializable ,\Countable
Datei TableArray.php
Date/Time modify File 2022-01-12 18:22:31
File-Size 53 KByte
MD5 File f87438fa82db5e9a8481ffdbe57470f9
Version 2.6
Date 2022-01-11

Public Methods

Methods and Parameter Description/Comments
final public function __construct($data = [], $filter = null) @param mixed : table array or iterator
@param mixed : $filter string or array or callable
@throws InvalidArgumentException
public static function create($data = [],$filter = null,...$addpar) create a instance
@param $data : 2 dim array, iterator or tableArray Instance
@param mixed : $filter string or array or callable
@return instance of tableArray
public static function createFromJson($jsonStr, $filter = null) create a instance from JSON-String
@param $jsonStr : represents a 2-dimensional array
@param mixed : $filter string or array or callable
@return instance of tableArray
public static function createFromXML($xml, $strXPath = null) create a instance from XML
@param $xml: xml-String or SimpleXML Object
@param $xpath: xpath-String (optional)
@return instance of tableArray
@throws InvalidArgumentException
public static function createFromOneDimArray(array $array, $delimiter = "") create from a numerical 1 dimensional array
@param $array 1 dim array
@param $delimiter delimiter for split rows
delimter one char, handle as csv
delimiter 2-4 chars, handle with explode
delimter >= 5 chars use as regular expression e.g '/^(\d+) (\d+):(\d+):(\d+)/'
delimter >= 5 chars and regular expression after s use preg_split
e.g 's/ +/' 2 or more spaces
public static function createFromString($input, $regExRow = ',', $regExSplitLines = '/\R/' ) create from string how get from file
@param string $input
@param string $regExRow for split rows
@param string $regExSplitLines for split lines
@throws InvalidArgumentException
public static function createFromCsvFile($file = null) create from string how get from file
@param string $file Filename or Wrapper
@return object
csv options must set with tableArray::setCsvDefaultOptions
@throws InvalidArgumentException
public static function createFromGroupedArray($input, array $keys = ['key']) create from grouped json-string or grouped array
@param string $input
@param array $keys : array of names for groupkeys
@throws InvalidArgumentException
public static function setCsvDefaultOptions(array $options) set default options for CSV
@param array options
@return true if ok, false if error
public static function check(array $data) check if data is a array with table-structure
@param $data : array
@return true ok or false
public static function allRowKeys(array $data) get keys from all rows
public static function unGroup(array $array, array $keys) ungroup data with array of given keys
@param array $array : input
@param array $keys : names for group keys
@return array
public static function wildcardMatch($pattern, $string) match strings with wildcards * and ?
@param string $pattern : String with wildcards how '*.2.?'
@param string $string : string how 'a.1.2.c'
@return bool
public static function arrayFilterRecursive(array $arr,callable $filter) Returns all filtered sub-arrays
@param array $arr
@param callable $filter param $current, $key, $it
@return array
public function addSqlFunction($name, $function) add a userfuction (closure)
@param string $name
@param string $function : closure
@return $this
public function addSqlFunctionFromArray(array $functions)
public function getSqlFunction($name) get a userfunction
@param string $name
@return closure or false if error
public function orderBy($sqlOrderTerm) sort with uasort
@param string $sqlOrderTerm: a string how for SQL OrderBy
@return $this
public function select($colKeys) set select
@param string or array
@return $this
@throws InvalidArgumentException
public function filterLikeAll($fieldName, $inList, $preserveKey = false) filter all rows with field is like all elements from array
@param $fieldName: key from a column
@param $inList : List of like-Terms
@return $this
public function filterLikeIn($fieldName, $inList, $preserveKey = false) filter all rows with field is like any element from array
@param $fieldName: key from a column
@param $inList : List of like-Terms
@return $this
public function filterEqual($field, $value = null) filter all rows with field = value, other remove
@param $field: fieldname or array(field => value)
@param @value: the value if $field
@return $this
public function filterUnique(array $fieldNames = null) filter all rows with field is unique from array
@param $fieldNames: array with fieldNames or null for all
@return $this
@throws InvalidArgumentException
public function filterGroupAggregate(array $aggregates, array $groups = [], $delim = ",") filterGroupAggregate
@param $aggregates: array with $fieldName => AggFunction
@param $groups: array with fieldnames for groups
@return $this
@throws InvalidArgumentException
public function filter($callback = null) filter all rows if $callback returns true
@param $callback: userfunction with parameter $row
if returnvalue from $callback is false current row will delete
if $callback == null: remove all rows with a null value
@return $this
public function walk($callback, $userParam = null) walk over all rows
@param $callback: userfunction with parameter $row, $key, $userParam
must return new array $row
if returnvalue from $callback is false current row will delete
if $callback == null: remove all rows with a null value
@return $this
public function transpose() transposes the array (switch rows and columns)
@return $this
public function merge($data) merge array
@param mixed $data : 2 dim array, iterator or tableArray Instance
@return $this
@throws Error
public function rectify() rectify: realizes uniform keys in all rows by adding missing keys
@return $this
@throws InvalidArgumentException
public function collectChilds(array $keyPatterns, $addFlatKeys = false) Get all child-arrays with keys defined in array of keyPatterns
@param array $keyPatterns : array with flatten keys with wildcards * and ?
@param bool $addFlatKeys : if true, add flatkeys
@return $this
public function innerJoinOn($ref, $tableAlias, $idRef, $refId) inner Join On
@param $ref array Reference
@param $idRef name id for ON from Reference-Array
@param $refId name id Basis-Array
@return $this
public function leftJoinOn($ref, $tableAlias, $idRef, $refId) left Join On
@param $ref array Reference
@param $idRef name id for ON from Reference-Array
@param $refId name id Basis-Array
@return $this
public function pivot($group, $pivot, $case) convert to pivot table
@param $group Field name for grouping
@param $pivot Field name for pivot
@param $case Field name for case
@return $this
public function offset($number) delete all rows < number
@param integer number
@return $this
public function limit($number) delete all rows > number
@param integer number
for number <0 count from end
@return $this
public function addKeys($newFieldName = "_key") add Keys from data as new column
@param string new Field Name
@return $this
public function fieldAsKey($fieldName = "_key") use a column as key for row
the column must contain unique values for new keys
@param string $fieldName
@return $this
@throws InvalidArgumentException
public function flatten($delimter = ".") flatten: flat all fields from row
public function addFlatKeys($delimter = ".") addFlatKeys: add flat cols from array-fields
public function fetchLimit($limit = 1, $start = 0, $preserveKey = false) get the array
@param: integer $limit > 0
@param: integer $start >= 0
@param: bool $preserveKey = false : new numeric key for result
@return array
public function fetchLimitFromEnd($limit = 1, $preserveKey = false) get limit elements from end
@param: integer $limit > 0
@param: bool $preserveKey = false : new numeric key for result
@return array
public function fetchAll() get the array
@return array
public function fetchAllObj() get array of stdClass-Objects
@return array
public function fetchAllAsJson($jsonOptions = 0) get array as JSON-String
@param int $jsonOptions
@return string
public function saveAsCsv($fileName) fetchAll and save it as csv-file
@param string $fileName
@return bool true/false
public function fetchAllAsCSV($fileName = "") get array as CSV-String or save as csv-file
@param string $fileName or ""
@return string or true/false if fileName used
@throws InvalidArgumentException
public function fetchKeyValue($fieldNameKey, $fieldNameValue) get a array(key => Value)
@return array
public function fetchColumn($fieldName) get 1 dimensional numerical array from column with fieldName
@param string fieldname
@return 1 dimensional numerical array or false if error
public function fetchColumnUnique($fieldName,$sort_flags = SORT_REGULAR) get 1 dimensional unique numerical array from column with fieldName
@param string fieldname
@return 1 dimensional numerical array or false if error
public function fetchRow($key = null) get row from given key
@param mixed $key, without $key get first row
@return one dimensional array or false if error
public function fetchRaw() get the array as raw (ignore select)
@return array
public function fetchGroup(array $groups) @param array $groups: array of max. 2 valid Fieldnames (key)
@return array of tabeles with $groupName as key
@throws InvalidArgumentException
public function setOption(array $options = []) set csv options
@param array $options option
@return $this
@throws InvalidArgumentException
public function getOption() get options array
@return array
public function fieldNameRaw($index = null) get the field name (key) for given index
@param integer $index
@return mixed field name (string) or a array of fieldnames if index = null
return false if index not exists
public function jsonSerialize() for JsonSerializable Interface
may use json_encode($sqlArrObj)
return array
public function count() for Countable Interface
may use count($sqlArrObj)
@return integer
public function firstRowToKey() remove first row and use it for keys
@return $this
public function toClass(/*'className', ...args */) change Class to continue method chaining
'className', ...args */
public function dprint($comment = "",$limit = 100) print for debug
@param string $comment
@param int $limit, default 100
@return $this
public function rewind() Iterator Methods
public function current()
public function key()
public function next() @return mixed
public function valid()
public function reset()

Constants

Declaration/Name Value Description/Comments
const CHECK_DATA_DURING_CONSTRUCT = false; false
const SEPARATOR = "\x02"; ''
const BOM = "\xef\xbb\xbf"; ''
STD_PROP_LIST 1 * Inherit
ARRAY_AS_PROPS 2 * Inherit