Normalize and json encode an array in order to compute it's hash
@param array $array
@param int $sort_flags
@param int $jsonEncodeOptions
@return false|string
345678
public static function normalizeAndSerializeArray(array &$array, int $sort_flags = SORT_REGULAR, int $jsonEncodeOptions = 0)
    {
        ArrayTool::normalizeArray($array, $sort_flags);
        return json_encode($array, $jsonEncodeOptions);
    }
832343
private function getSortArrayParameter($sortCondition)
    {
        $sortArray = [
            $sortCondition['column']->getUniqueId(),
        ];

        if ('DESC' === $sortCondition['sortDirection']) {
            $desc = SORT_DESC;
            $sortArray[] = $desc;
        } else {
            $asc = SORT_ASC;
            $sortArray[] = $asc;
        }

        switch (get_class($sortCondition['column']->getType())) {
            case Column\Type\Number::class:
                $numeric = SORT_NUMERIC;
                $sortArray[] = $numeric;
                break;

            case Column\Type\PhpString::class:
                $string = SORT_NATURAL | SORT_FLAG_CASE;
                $sortArray[] = $string;
                break;

            default:
                $regular = SORT_REGULAR;
                $sortArray[] = $regular;
                break;
        }

        return $sortArray;
    }
1027637
public function toJson($options = 0)
	{
		$json = json_encode($this->jsonSerialize(), $options);

		if (JSON_ERROR_NONE !== json_last_error()) {
			throw JsonEncodingException::forObject($this, json_last_error_msg());
		}

		return $json;
	}
44341
public function sort($sort_flags = SORT_REGULAR): SplArray
    {
        $temp = $this->getArrayCopy();
        sort($temp, $sort_flags);
        return new SplArray($temp);
    }
725407
public function normalizeArray($array, $sort = true) {
        $output = array();

        if ($array) {
            foreach ($array as $key => $value) {
                if (is_numeric($key)) {
                    $output[] = $value;
                } else {
                    $output[] = $key;
                }
            }

            if ($sort) {
                sort($output);
            }
        }

        return $output;
    }
600980
protected function jsonEncode(array $data)
    {
        set_error_handler(function () {
            $this->handleJsonError(JSON_ERROR_SYNTAX);
        }, E_WARNING);
        
        $json = json_encode($data, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
        restore_error_handler();
        $this->handleJsonError(json_last_error());
        
        return $json;
    }
821726
public function jsonp_decode($jsonp, $assoc = false)
	{
		$jsonp = trim($jsonp);
		if(isset($jsonp[0]) && $jsonp[0] !== '[' && $jsonp[0] !== '{') {
			$begin = strpos($jsonp, '(');
			if(false !== $begin)
			{
				$end = strrpos($jsonp, ')');
				if(false !== $end)
				{
					$jsonp = substr($jsonp, $begin + 1, $end - $begin - 1);
				}
			}
		}
		return json_decode($jsonp, $assoc);
	}
24030
protected function _sortResult(array &$result, $sort = 'asort')
    {
        // Sorting
        switch ($sort) {
            case 'asort':
                asort($result);
                break;

            case 'ksort':
                ksort($result);
                break;

            case 'natsort':
                natsort($result);
                break;

            default:
                $sort($result);
        }
    }
216242
public static function asort(array &$array, int $sort_flags = SORT_REGULAR): void
    {
        self::decorateOriginalArray($array);
        uasort($array, function ($a, $b) use ($sort_flags) {
            if ($a[1] == $b[1])
                return $a[0] - $b[0];
            $arr = [
                - 1 => $a[1],
                1 => $b[1]
            ];
            asort($arr, $sort_flags);
            reset($arr);
            return key($arr);
        });
        self::undecorateSortedArray($array);
    }
297425
protected function encodeOptions(array $options) {
        if (0 === count($options)) {
            return "{}";
        }
        ksort($options);
        $output = json_encode($options, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
        return str_replace("\n", "\n        ", $output);
    }
389728
function sort(array &$var,$col,$order=SORT_ASC) {
		uasort(
			$var,
			function($val1,$val2) use($col,$order) {
				list($v1,$v2)=[$val1[$col],$val2[$col]];
				$out=is_numeric($v1) && is_numeric($v2)?
					Base::instance()->sign($v1-$v2):strcmp($v1,$v2);
				if ($order==SORT_DESC)
					$out=-$out;
				return $out;
			}
		);
		$var=array_values($var);
	}
1116697
protected function encodeMethodCalls($methodCalls, Encoder $encoder, $flags = null)
    {
        $buffer = '';
        $flags  = Flags::add(Flags::CLOSE_STATEMENT, $flags);

        foreach ($methodCalls as $call) {
            $buffer .= "\n" . $call->encode($encoder, $flags);
        }

        return $buffer;
    }
585365
public function sort(array $array): array {
        $array = \array_values($array);
        $length = \count($array);

        if (0 === $length || 1 === $length) return $array;

        for ($i = 0; $i < $length; $i++) {
            $min = $i;
            for ($j = $i; $j < $length; $j++) {
                if (Comparator::lessThan($array[$j], $array[$min])) {
                    $min = $j;
                }
            }
            $tmp = $array[$min];
            $array[$min] = $array[$i];
            $array[$i] = $tmp;
        }
        return $array;
    }
1362114
public function encode(array $options = [])
    {
        $options = array_replace(
            [
                'encodingOptions'       => $this->getOption('encodingOptions')
            ],
            $options
        );

        $json = json_encode($this->getContents(), $options['encodingOptions']);

        if ($json === false) {
            switch (json_last_error()) {
                case JSON_ERROR_DEPTH:
                    $msg = 'The maximum stack depth has been exceeded.';

                    break;
                case JSON_ERROR_STATE_MISMATCH:
                    $msg = 'Occurs with underflow or with the modes mismatch.';

                    break;
                case JSON_ERROR_CTRL_CHAR:
                    $msg = 'Control character error, possibly incorrectly encoded.';

                    break;
                case JSON_ERROR_UTF8:
                    $msg = 'alformed UTF-8 characters, possibly incorrectly encoded.';

                    break;
                default:
                    $msg = 'Unknown error';
            }

            throw EncodeException::create($this->getPath(), $msg);
        }

        return $json;
    }
780151
public function applySorting ($sortMapping, array $where = []) : bool
    {
        if (!\is_array($sortMapping) || empty($sortMapping))
        {
            // if value is not in correct format or an empty array.
            return false;
        }

        $all = $this->getAllEntities($where);

        // check sort values
        $possibleSortValues = \range(0, \count($all) - 1);

        if (!$this->arraysAreIdentical($possibleSortValues, \array_values($sortMapping)))
        {
            // the given sort values are wrong
            return false;
        }

        // check item ids
        $allIds = \array_map(function (SortableEntityInterface $entity) { return $entity->getId(); }, $all);

        if (!$this->arraysAreIdentical($allIds, \array_keys($sortMapping)))
        {
            // the given item ids are wrong
            return false;
        }

        foreach ($all as $entity)
        {
            $entity->setSortOrder($sortMapping[$entity->getId()]);
        }

        return true;
    }
466936
function decode($json, $assoc = true, $depth = 512, $options = 0) {
        if (array_contains(['', null], $json)) {
            return null;
        }

        $data = @json_decode($json, $assoc, $depth, $options);
        
        if ($data === null && json_last_error() !== JSON_ERROR_NONE) {
            throw new JsonDecodeException(json_last_error_msg(), $json);
        }

        return $data;
    }
340930
private static function replaceArrayByMap($json, array $arrayKeys)
    {
        preg_match_all(self::ARRAY_KEYS_REGEX, $json, $matches, PREG_SET_ORDER);

        foreach ($matches as $match) {
            if (!\in_array($match[1], $arrayKeys, true)) {
                $replace = str_replace('[]', '{}', $match[0]);
                $json = str_replace($match[0], $replace, $json);
            }
        }

        return $json;
    }