Ensures passed var is an array

@param mixed   $var
@param boolean $deep

@return array
484979
public static function convertToArray($var, $deep = false)
    {
        if (null === $var) {
            return [];
        }
        if (is_scalar($var)) {
            return [$var];
        }
        if (is_object($var)) {
            if ($var instanceof \stdClass) {
                $var = (array)$var;
            } elseif ($var instanceof Collection) {
                $var = $var->all();
            } elseif ($var instanceof \Iterator) { // @codeCoverageIgnore
                $var = iterator_to_array($var);
            } elseif ($var instanceof \ArrayObject) { // @codeCoverageIgnore
                $var = $var->getArrayCopy();
            } elseif (method_exists($var, 'toArray')) {
                $var = $var->toArray();
            } elseif (method_exists($var, 'asArray')) {
                $var = $var->asArray();
            } elseif (method_exists($var, 'toJson')) {
                $var = json_decode($var->toJson(), true);
            } elseif (method_exists($var, 'asJson')) {
                $var = json_decode($var->asJson(), true);
            }

            return $var;
        }
        if (is_array($var)) {
            if ($deep) {
                foreach ($var as &$item) {
                    $item = static::convertToArray($item, true);
                }
            }

            return $var;
        }

        return [$var]; // @codeCoverageIgnore
    }
148696
function varIsArray($var)
		{
			$var_ser = serialize($var);
			array_push($this->arrHistory, $var_ser);

			$this->makeTableHeader("array","array");
			if(Arrays::isArray($var)) {
				foreach($var as $key => $value) {
					$this->makeTDHeader("array", $key);

					//check for recursion
					if(Arrays::isArray($value)) {
						$var_ser = serialize($value);
						if(Arrays::inArray($var_ser, $this->arrHistory, TRUE))
							$value = "*RECURSION*";
					}

					if(Arrays::inArray(gettype($value), $this->arrType)) {
						$this->checkType($value);
					} else {
						$value = (trim($value)=="") ? "[empty string]" : $value;
						echo $value;
					}
					echo $this->closeTDRow();
				}
			} else {
				echo "<tr><td>" . $this->error("array") . $this->closeTDRow();
			}
			array_pop($this->arrHistory);
			echo "</table><hr class=thinDebugHr />";
		}
879576
public function stringDotsToArrayKeys($variable, $depth = 7)
    {
        /**
         *
         * -- Todo: Rewrite this regex --
         *  
        */
        return preg_replace_callback('/\$(\w+)\.(\w+)(\.(\w+)(\.(\w+)(\.(\w+)(\.(\w+)(\.(\w+)?)?)?)?)?)?/s', function ($matches) {
            switch (count($matches)) {
                case 3:
                    $var = $this->calculateSubKeys($matches, 1);
                break;

                case 5:
                    $var = $this->calculateSubKeys($matches, 2);
                break;

                case 7:
                    $var = $this->calculateSubKeys($matches, 3);
                break;

                case 9:
                    $var = $this->calculateSubKeys($matches, 4);
                break;

                case 11:
                    $var = $this->calculateSubKeys($matches, 5);
                break;

                case 13:
                    $var = $this->calculateSubKeys($matches, 6);
                break;

                case 14:
                    $var = $this->calculateSubKeys($matches, 7);
                break;

                default:
                    $var = $variable;
            }

            return $var;
        },
        $variable);
    }
1045974
public function limit($var, $depth, array &$references = [])
    {
        if ($depth > $this->depthLimit) {
            return '*DEPTH LIMIT*';
        }

        if (is_array($var)) {
            return $this->limitArray($var, $depth, $references);
        }

        if (is_object($var)) {
            return $this->limitObject($var, $depth, $references);
        }

        return $var;
    }
971377
protected static function encodeArrayVariable(array $variable, array $value, $operator, $separator, &$useQueryString)
    {
        $isAssociativeArray = self::isAssociative($variable);
        $keyValuePairs = [];

        foreach ($variable as $key => $var) {
            if ($isAssociativeArray) {
                $key = rawurlencode($key);
                $isNestedArray = is_array($var);
            } else {
                $isNestedArray = false;
            }

            if (!$isNestedArray) {
                $var = rawurlencode($var);
                if ($operator === '+' || $operator === '#') {
                    $var = self::decodeReservedDelimiters($var);
                }
            }

            if ($value['modifier'] === '*') {
                if ($isAssociativeArray) {
                    if ($isNestedArray) {
                        // allow for deeply nested structures
                        $var = strtr(http_build_query([$key => $var]), ['+' => '%20', '%7e' => '~']);
                    } else {
                        $var = $key . '=' . $var;
                    }
                } elseif ($key > 0 && $useQueryString) {
                    $var = $value['value'] . '=' . $var;
                }
            }

            $keyValuePairs[$key] = $var;
        }

        $expanded = '';
        if (empty($variable)) {
            $useQueryString = false;
        } elseif ($value['modifier'] === '*') {
            $expanded = implode($separator, $keyValuePairs);
            if ($isAssociativeArray) {
                // Don't prepend the value name when using the explode modifier with an associative array
                $useQueryString = false;
            }
        } else {
            if ($isAssociativeArray) {
                // The result must be a comma separated list of keys followed by their respective values
                // if the explode modifier is not set on an associative array
                foreach ($keyValuePairs as $k => &$v) {
                    $v = $k . ',' . $v;
                }
            }
            $expanded = implode(',', $keyValuePairs);
        }

        return $expanded;
    }
748828
protected function varToString($var)
    {
        if (is_object($var)) {
            return get_class($var);
        }

        if (is_array($var)) {
            return 'Array';
        }

        if (is_resource($var)) {
            return sprintf('Resource(%s)', get_resource_type($var));
        }

        if (null === $var) {
            return 'null';
        }

        if (false === $var) {
            return 'false';
        }

        if (true === $var) {
            return 'true';
        }

        return (string) gettype($var);
    }
384070
public function toArray($filterVariableContent = false, &$filtered = array()){

        $data = array(
            'serial' => $this->getSerial(),
            'body' => $this->getBody(),
            'elements' => $this->getArraySerializedElementCollection($this->getElements(), $filterVariableContent, $filtered),
        );
        
        if(DEBUG_MODE){
            //in debug mode, add debug data, such as the related item
            $data['debug'] = array('relatedItem' => is_null($this->getRelatedItem())?'':$this->getRelatedItem()->getSerial());
        }   
        
        return $data;
    }
11100
public static function var_dump($var, $return = false, $expandLevel = 1)
    {
        self::$hasArray = false;
        $toggScript = 'var colToggle = function(toggID) {var img = document.getElementById(toggID);if (document.getElementById(toggID + "-collapsable").style.display == "none") {document.getElementById(toggID + "-collapsable").style.display = "inline";setImg(toggID, 0);var previousSibling = document.getElementById(toggID + "-collapsable").previousSibling;while (previousSibling != null && (previousSibling.nodeType != 1 || previousSibling.tagName.toLowerCase() != "br")) {previousSibling = previousSibling.previousSibling;}} else {document.getElementById(toggID + "-collapsable").style.display = "none";setImg(toggID, 1);var previousSibling = document.getElementById(toggID + "-collapsable").previousSibling; while (previousSibling != null && (previousSibling.nodeType != 1 || previousSibling.tagName.toLowerCase() != "br")) {previousSibling = previousSibling.previousSibling;}}};';
        $imgScript = 'var setImg = function(objID,imgID,addStyle) {var imgStore = ["data:image/png;base64,' . self::$icon_collapse . '", "data:image/png;base64,' . self::$icon_expand . '"];if (objID) {document.getElementById(objID).setAttribute("src", imgStore[imgID]);if (addStyle){document.getElementById(objID).setAttribute("style", "position:relative;left:-5px;top:-1px;cursor:pointer;");}}};';
        $jsCode = preg_replace('/ +/', ' ', '<script>' . $toggScript . $imgScript . '</script>');
        $html = '<pre style="margin-bottom: 18px;' .
            'background: #f7f7f9;' .
            'border: 1px solid #e1e1e8;' .
            'padding: 8px;' .
            'border-radius: 4px;' .
            '-moz-border-radius: 4px;' .
            '-webkit-border radius: 4px;' .
            'display: block;' .
            'font-size: 12.05px;' .
            'white-space: pre-wrap;' .
            'word-wrap: break-word;' .
            'color: #333;' .
            'font-family: Menlo,Monaco,Consolas,\'Courier New\',monospace;">';
        $done  = array();
        $html .= self::recursiveVarDumpHelper($var, intval($expandLevel), 0, $done);
        $html .= '</pre>';

        if (self::$hasArray) {
            $html = $jsCode . $html;
        }

        if (!$return) {
            echo $html;
        }

        return $html;
    }
562094
private function mergeArrays($deep, $array1, $array2)
    {
        if ($deep === 'merge') {
            return Utils::arrayMergeRecursiveUnique($array1, $array2);
        }
        if ($deep === true) {
            return array_replace_recursive($array1, $array2);
        }

        return array_merge($array1, $array2);
    }
640629
private function parseArray(array &$var, BasicObject $o)
    {
        $array = new BasicObject();
        $array->transplant($o);
        $array->size = \count($var);

        if (isset($var[$this->marker])) {
            --$array->size;
            $array->hints[] = 'recursion';

            $this->applyPlugins($var, $array, self::TRIGGER_RECURSION);

            return $array;
        }

        $rep = new Representation('Contents');
        $rep->implicit_label = true;
        $array->addRepresentation($rep);
        $array->value = $rep;

        if (!$array->size) {
            $this->applyPlugins($var, $array, self::TRIGGER_SUCCESS);

            return $array;
        }

        if ($this->depth_limit && $o->depth >= $this->depth_limit) {
            $array->hints[] = 'depth_limit';

            $this->applyPlugins($var, $array, self::TRIGGER_DEPTH_LIMIT);

            return $array;
        }

        $copy = \array_values($var);

        // It's really really hard to access numeric string keys in arrays,
        // and it's really really hard to access integer properties in
        // objects, so we just use array_values and index by counter to get
        // at it reliably for reference testing. This also affects access
        // paths since it's pretty much impossible to access these things
        // without complicated stuff you should never need to do.
        $i = 0;

        // Set the marker for recursion
        $var[$this->marker] = $array->depth;

        $refmarker = new stdClass();

        foreach ($var as $key => &$val) {
            if ($key === $this->marker) {
                continue;
            }

            $child = new BasicObject();
            $child->name = $key;
            $child->depth = $array->depth + 1;
            $child->access = BasicObject::ACCESS_NONE;
            $child->operator = BasicObject::OPERATOR_ARRAY;

            if (null !== $array->access_path) {
                if (\is_string($key) && (string) (int) $key === $key) {
                    $child->access_path = 'array_values('.$array->access_path.')['.$i.']'; // @codeCoverageIgnore
                } else {
                    $child->access_path = $array->access_path.'['.\var_export($key, true).']';
                }
            }

            $stash = $val;
            $copy[$i] = $refmarker;
            if ($val === $refmarker) {
                $child->reference = true;
                $val = $stash;
            }

            $rep->contents[] = $this->parse($val, $child);
            ++$i;
        }

        $this->applyPlugins($var, $array, self::TRIGGER_SUCCESS);
        unset($var[$this->marker]);

        return $array;
    }
124076
function transpose(array &$var) {
		$out=[];
		foreach ($var as $keyx=>$cols)
			foreach ($cols as $keyy=>$valy)
				$out[$keyy][$keyx]=$valy;
		$var=$out;
	}
658454
public function wrapping($var, array $references = [], $depth = 0)
    {
        switch (true) {
            case is_object($var):
                if ($depth > 2) return '[object]';

                // is recruision ?
                if (in_array($var, $references, true)) return '** recursion **';
                $references[] = $var;

                $ref = new ReflectionObject($var);
                $values = [];
                foreach ($ref->getProperties() as $property) {

                    // simplize
                    $property->setAccessible(true);
                    $v = $property->getValue($var);
                    if (array_key_exists('Samurai\Raikiri\DependencyInjectable', $this->class_uses_deep($ref->getName()))
                        && $property->getName() === 'container') $v = '** raikiri **';
                    if ($var instanceof EntityTable && $property->getName() === 'onikiri') $v = '** onikiri **';

                    $values[] = sprintf('%s: %s', $property->getName(), $this->wrapping($v, $references, $depth + 1));
                }
                $value = sprintf('%s {%s}', $ref->getName(), join(', ', $values));
                break;
            case is_array($var):
                if ($depth > 2) return '[array]';

                $values = [];
                foreach ($var as $key => $value) {
                    if (is_int($key)) {
                        $values[] = sprintf('%s', $this->wrapping($value, $references, $depth + 1));
                    } else {
                        $values[] = sprintf('%s: %s', $key, $this->wrapping($value, $references, $depth + 1));
                    }
                }
                $value = sprintf('[%s]', join(', ', $values));
                break;
            case $var === null:
                $value = 'NULL';
                break;
            default:
                $value = $var;
                break;
        }
        return $value;
    }
775757
private function deepMxCheck(array $value = []): bool
    {
        $isValid = false;
        foreach ($value as $host => $weight) {
            $res = $this->isReserved($host);
            if (!$res && (\checkdnsrr($host, 'A') || \checkdnsrr($host, 'AAAA') || \checkdnsrr($host, 'A6'))) {
                $isValid = true;
                break;
            }
        }
        return $isValid;
    }
1244435
protected function varToString($var)
    {
        if (is_object($var)) {
            return sprintf('Object(%s)', get_class($var));
        }

        if (is_array($var)) {
            $a = array();
            foreach ($var as $k => $v) {
                $a[] = sprintf('%s => %s', $k, $this->varToString($v));
            }

            return sprintf("Array(%s)", implode(', ', $a));
        }

        if (is_resource($var)) {
            return sprintf('Resource(%s)', get_resource_type($var));
        }

        if (null === $var) {
            return 'null';
        }

        if (false === $var) {
            return 'false';
        }

        if (true === $var) {
            return 'true';
        }

        return (string) "'$var'";
    }
298500
protected function _arrayToString(array $var)
    {
        foreach ($var as $rowIndex => $row) {
            foreach ($row as $k => $v) {
                if (is_resource($var[$rowIndex][$k])) {
                    $var[$rowIndex][$k] = stream_get_contents($v);
                }
            }
        }

        $var = json_decode(str_replace(['(', ')'], ['&#40', '&#41'], json_encode($var)), true);
        $var = var_export($var, true);

        return str_replace(['array (', ')', '&#40', '&#41'], ['[', ']', '(', ')'], $var);
    }
1124419
private function unique($var)
	{
		if (is_array($var))
		{
			// We only want to get unique items if they aren't associative
			if (isset($var[0]))
			{
				// Serialize vars, unique them, then unserialize
				$var = array_map('unserialize', array_unique(array_map('serialize', $var)));
			}

			foreach ($var as &$sub)
			{
				if (is_array($sub))
				{
					$sub = $this->unique($sub);
				}
			}
		}

		return $var;
	}
1112691
public function get($key, $default = null, $deep = false)
    {
        if (is_array($key)) {
            $request = [];
            foreach ($key as $k) {
                $_default = is_array($default) && isset($default[$k]) ? $default[$k] : null;
                $request[$k] = parent::get($k, $_default);
            }
        }
        else {
            $request = parent::get($key, $default);
        }

        return $request;
    }