{@inheritdoc}

@link   http://steindom.com/articles/shortest-php-code-convert-csv-associative-array
325929
public function toJson ()
    {
        $rows    = array_map("str_getcsv", explode("\n", trim($this->data)));
        $columns = array_shift($rows);
        $csv     = array();

        foreach ($rows as $row)
        {
            $csv[] = array_combine($columns, $row);
        }

        return json_encode($csv);
    }
610850
public function import($csv)
    {
        // convert to UTF-8
        $head      = substr($csv, 0, 4096);
        $charset   = rcube_charset::detect($head, RCUBE_CHARSET);
        $csv       = rcube_charset::convert($csv, $charset);
        $csv       = preg_replace(array('/^[\xFE\xFF]{2}/', '/^\xEF\xBB\xBF/', '/^\x00+/'), '', $csv); // also remove BOM
        $head      = '';
        $prev_line = false;

        $this->map       = array();
        $this->gmail_map = array();

        // Parse file
        foreach (preg_split("/[\r\n]+/", $csv) as $line) {
            if (!empty($prev_line)) {
                $line = '"' . $line;
            }

            $elements = $this->parse_line($line);

            if (empty($elements)) {
                continue;
            }

            // Parse header
            if (empty($this->map)) {
                $this->parse_header($elements);
                if (empty($this->map)) {
                    break;
                }
            }
            // Parse data row
            else {
                // handle multiline elements (e.g. Gmail)
                if (!empty($prev_line)) {
                    $first = array_shift($elements);

                    if ($first[0] == '"') {
                        $prev_line[count($prev_line)-1] = '"' . $prev_line[count($prev_line)-1] . "\n" . substr($first, 1);
                    }
                    else {
                        $prev_line[count($prev_line)-1] .= "\n" . $first;
                    }

                    $elements = array_merge($prev_line, $elements);
                }

                $last_element = $elements[count($elements)-1];
                if ($last_element[0] == '"') {
                    $elements[count($elements)-1] = substr($last_element, 1);
                    $prev_line = $elements;
                    continue;
                }
                $this->csv_to_vcard($elements);
                $prev_line = false;
            }
        }
    }
188724
static function toArray($kvs, $strict=false)
    {
        $lines = explode("\n", $kvs);

        $last = array_pop($lines);
        if ($last !== '') {
            array_push($lines, $last);
            if ($strict) {
                return false;
            }
        }

        $values = array();

        for ($lineno = 0; $lineno < count($lines); $lineno++) {
            $line = $lines[$lineno];
            $kv = explode(':', $line, 2);
            if (count($kv) != 2) {
                if ($strict) {
                    return false;
                }
                continue;
            }

            $key = $kv[0];
            $tkey = trim($key);
            if ($tkey != $key) {
                if ($strict) {
                    return false;
                }
            }

            $value = $kv[1];
            $tval = trim($value);
            if ($tval != $value) {
                if ($strict) {
                    return false;
                }
            }

            $values[$tkey] = $tval;
        }

        return $values;
    }
355347
public function getStmt()
    {
        // Make sure there are no nested arrays
        if (ArrayUtils::hasAtLeastOneArrayValue($this->bindings)) {
            throw new RuntimeException('PDO bindings can not contain nested arrays');
        }

        // Build target query before bindings are cleared purely for logging purpose
        $log = str_replace(array_keys($this->bindings), array_values($this->bindings), $this->queryBuilder->getQueryString());

        // Execute it
        $stmt = $this->pdo->prepare($this->queryBuilder->getQueryString());
        $stmt->execute($this->bindings);

        // Log target query
        $this->queryLogger->add($log);

        // Clear the buffer
        $this->clear();

        return $stmt;
    }
862092
public function toArray()
    {
        $arr = [];
        // 从保存未定义属性的变量中读取字段kv
        foreach ($this->attrs as $field => $value) {
            $arr[$field] = $value;
        }

        // 从指定的属性中读取字段kv
        foreach ($this->columnMap as $field => $attr) {
            if (property_exists($this, $attr)) {
                $arr[$field] = $this->$attr;
            } else {
                unset($arr[$field]);
            }
        }

        return $arr;
    }
1150951
private function arrayPair() {
    if ($this->currentType === '&') {
      return $this->writeVariable();
    }
    $node = $this->expr();
    if ($this->currentType === T_DOUBLE_ARROW) {
      $expr = $node;
      $node = new ArrayPairNode();
      $node->addChild($expr, 'key');
      $this->mustMatch(T_DOUBLE_ARROW, $node);
      if ($this->currentType === '&') {
        $node->addChild($this->writeVariable(), 'value');
      }
      else {
        $node->addChild($this->expr(), 'value');
      }
    }
    return $node;
  }
1227199
public function asArray($key = null, $value = null)
    {
        if (!is_null($key))
        {
            Helpers\Validate::table($this->name)->field($key);
        }
        if (!is_null($value))
        {
            Helpers\Validate::table($this->name)->field($value);
        }

        $datas = array();
        if (!$this->resetKeys)
        {
            if (is_null($key) && is_null($value))
            {
                return $this->data;
            }
            else
            {
                foreach ($this->data as $rowKey => $data)
                {
                    $datas[$rowKey] = array();
                    foreach ($data as $row)
                    {
                        if (is_null($key))
                        {
                            $datas[$rowKey][] = $row->{$value};
                        }
                        elseif (is_null($value))
                        {
                            $datas[$rowKey][$row->{$key}] = $row;
                        }
                        else
                        {
                            $datas[$rowKey][$row->{$key}] = $row->{$value};
                        }
                    }
                }
            }
        }
        else
        {
            if (is_null($key) && is_null($value))
            {
                foreach ($this->data as $data)
                {
                    $datas[] = get_object_vars($data);
                }
            }
            else
            {
                foreach ($this->data as $data)
                {
                    if (is_null($key))
                    {
                        $datas[] = $data->{$value};
                    }
                    elseif (is_null($value))
                    {
                        $datas[$data->{$key}] = $data;
                    }
                    else
                    {
                        $datas[$data->{$key}] = $data->{$value};
                    }
                }
            }
        }

        return $datas;
    }
1057437
public function serializePHP($array)
    {
        $raw = '';
        $line = 0;
        $keys = array_keys($array);

        foreach ($keys as $key) {
            $value = $array[$key];
            $line++;
            $raw .= $key . '|';
            if (is_array($value) && isset($value['huge_recursion_blocker_we_hope'])) {
                $raw .= 'R:' . $value['huge_recursion_blocker_we_hope'] . ';';
            } else {
                $raw .= serialize($value);
            }
            $array[$key] = array('huge_recursion_blocker_we_hope' => $line);
        }

        return $raw;
    }
1370676
private function _fromAssociativeArray(array $array)
    {
        foreach ($this->_fields as $fieldName => $field) {
            $fieldType = $field['FieldType'];   
            if (is_array($fieldType)) {
                if ($this->_isComplexType($fieldType[0])) {
                    if (array_key_exists($fieldName, $array)) { 
                        $elements = $array[$fieldName];
                        if (!$this->_isNumericArray($elements)) {
                            $elements =  array($elements);    
                        }
                        if (count ($elements) >= 1) {
                            // // require_once (dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $fieldType[0]) . ".php");

                            foreach ($elements as $element) {
                                $this->_fields[$fieldName]['FieldValue'][] = new $fieldType[0]($element);
                            }
                        }
                    } 
                } else {
                    if (array_key_exists($fieldName, $array)) {
                        $elements = $array[$fieldName];
                        if (!$this->_isNumericArray($elements)) {
                            $elements =  array($elements);    
                        }
                        if (count ($elements) >= 1) {
                            foreach ($elements as $element) {
                                $this->_fields[$fieldName]['FieldValue'][] = $element;
                            }
                        }  
                    }
                }
            } else {
                 if ($this->_isComplexType($fieldType)) {
                    if (array_key_exists($fieldName, $array)) {
                        // // require_once (dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $fieldType) . ".php");
                        $this->_fields[$fieldName]['FieldValue'] = new $fieldType($array[$fieldName]);
                    }   
                 } else {
                    if (array_key_exists($fieldName, $array)) {
                        $this->_fields[$fieldName]['FieldValue'] = $array[$fieldName];
                    }
                 }
            }
        }
    }
473194
private function convertHashToArrayOfBoolean()
    {
        $matches = str_split($this->hash, 1);
        foreach ($matches as $i => $match) {
            $index = (int) ($i / $this->block);
            $data = $this->convertHexaToBool($match);
            $items = [
                0 => [0, 2],
                1 => [1, 4],
                2 => [2, 6],
                3 => [3, 8],
            ];
            foreach ($items[$i % $this->block] as $item) {
                $this->arrayOfSquare[$index][$item] = $data;
            }

            ksort($this->arrayOfSquare[$index]);
        }
        preg_match_all('/(\d)[\w]/', $this->hash, $matches);
        $this->color = array_map(function ($data) {
            return hexdec($data) * 16;
        }, array_reverse($matches[1]));

        return $this;
    }
695213
public function getArrayCopy()
    {
        $fields = $this->columns;

        foreach ($fields as $fieldName => $fieldValue) {
            if ($this->isJSON($fieldValue)) {
                $fields[ $fieldName ] = new Columns\DataJSON(json_decode($fieldValue, true));
            } elseif ($this->isSerialized($fieldValue)) {
                $fields[ $fieldName ] = new Columns\DataSerialize(unserialize($fieldValue));
            } else {
                $fields[ $fieldName ] = $fieldValue;
            }
        }

        return $fields;
    }
1298966
private function convertHashToArrayOfBoolean()
    {
        preg_match_all('/(\w)(\w)/', $this->hash, $chars);

        foreach ($chars[1] as $i => $char) {
            $index = (int) ($i / 3);
            $data = $this->convertHexaToBoolean($char);

            $items = [
                0 => [0, 4],
                1 => [1, 3],
                2 => [2],
            ];

            foreach ($items[$i % 3] as $item) {
                $this->arrayOfSquare[$index][$item] = $data;
            }

            ksort($this->arrayOfSquare[$index]);
        }

        $this->color = array_map(function ($data) {
            return hexdec($data) * 16;
        }, array_reverse($chars[1]));

        return $this;
    }
1058568
function _uri_to_assoc($n=3, $default=array(), $which='segment') {
		if ($which == 'segment') {
			$total_segments='total_segments';
			$segment_array='segment_array';
		} else {
			$total_segments='total_rsegments';
			$segment_array='rsegment_array';
		}

		if (!is_numeric($n)) {
			return $default;
		}

		if (isset($this->keyval[$n])) {
			return $this->keyval[$n];
		}

		if ($this->$total_segments() < $n) {
			if (count($default) == 0) {
				return array ();
			}

			$retval=array ();
			foreach ( $default as $val ) {
				$retval[$val]=FALSE;
			}
			return $retval;
		}

		$segments=array_slice($this->$segment_array(), ($n - 1));

		$i=0;
		$lastval='';
		$retval=array ();
		foreach ( $segments as $seg ) {
			if ($i % 2) {
				$retval[$lastval]=$seg;
			} else {
				$retval[$seg]=FALSE;
				$lastval=$seg;
			}

			$i++;
		}

		if (count($default) > 0) {
			foreach ( $default as $val ) {
				if (!array_key_exists($val, $retval)) {
					$retval[$val]=FALSE;
				}
			}
		}

		// Cache the array for reuse
		$this->keyval[$n]=$retval;
		return $retval;
	}
1180235
static function deserialize($class_name, $assoc_s)
    {
        $pairs = Auth_OpenID_KVForm::toArray($assoc_s, $strict = true);
        $keys = array();
        $values = array();
        foreach ($pairs as $key => $value) {
            if (is_array($value)) {
                list($key, $value) = $value;
            }
            $keys[] = $key;
            $values[] = $value;
        }

        $class_vars = get_class_vars($class_name);
        $class_assoc_keys = $class_vars['assoc_keys'];

        sort($keys);
        sort($class_assoc_keys);

        if ($keys != $class_assoc_keys) {
            trigger_error('Unexpected key values: ' . var_export($keys, true),
                          E_USER_WARNING);
            return null;
        }

        $version = $pairs['version'];
        $handle = $pairs['handle'];
        $secret = $pairs['secret'];
        $issued = $pairs['issued'];
        $lifetime = $pairs['lifetime'];
        $assoc_type = $pairs['assoc_type'];

        if ($version != '2') {
            trigger_error('Unknown version: ' . $version, E_USER_WARNING);
            return null;
        }

        $issued = intval($issued);
        $lifetime = intval($lifetime);
        $secret = base64_decode($secret);

        return new $class_name(
            $handle, $secret, $issued, $lifetime, $assoc_type);
    }
24425
public static function normalize($headers, $associative = true)
    {
        $normalizedHeaders = [];

        if (!$associative) {
            $headers = self::normalize($headers);
        }

        foreach (HeadersParser::parse($headers) as $name => $value) {
            if (strpos($value, 'HTTP/') === 0) {
                continue;
            }

            list($name, $value) = explode(':', $value, 2);

            $name = self::normalizeHeaderName($name);
            $value = self::normalizeHeaderValue($value);

            if (!$associative) {
                $normalizedHeaders[] = $name.': '.$value;
            } else {
                $normalizedHeaders[$name] = isset($normalizedHeaders[$name])
                    ? $normalizedHeaders[$name].', '.$value
                    : $value;
            }
        }

        return $normalizedHeaders;
    }
141409
public function toArray() {
        $colsArray = $this->getColArray();
        
        $rowsArray = $this->rows;
        
        array_walk($rowsArray, function (&$item) {
            $item = array('c' => $item->toArray());
        });
        
        //remove nulls
        return self::getFilteredArray($colsArray, $rowsArray, $this->p);
        
    }
629306
static function arrayToCode(array $arrray, array $syntax, $indent = '    ', &$indentLevel = 1)
    {
        $result = "";
        $ia_accos = F::isAssoc($arrray);
        foreach ($arrray as $key => $value){
            $result .= str_repeat($indent, $indentLevel);
            $result .= $ia_accos ? ((is_int($key) ? $key : "'" . addslashes($key) . "'") . ' => ') : '';
            if (is_array($value)){
                if ($value === []) {
                    $result .= $syntax['open'] . $syntax['close'] . ",\n";
                }else{
                    $indentLevel++;
                    $result .= $syntax['open'] . "\n"
                        . self::arrayToCode($value, $syntax, $indent, $indentLevel)
                        . str_repeat($indent, --$indentLevel) . $syntax['close'] . ",\n";
                }
            }else
            if (is_object($value) || is_string($value)){
                $result .= var_export($value, true) . ",\n";
            }else
            if (is_bool($value)){
                $result .= ($value ? 'true' : 'false') . ",\n";
            }else
            if ($value === null){
                $result .= "null,\n";
            }else{
                $result .= $value . ",\n";
            }
        }
        return $result;
    }