Skip to content
Snippets Groups Projects
Arr.php 630 B
Newer Older
<?php

namespace IQDEV\ElasticSearchTests\Helpers;

class Arr
{
Vadim Galizyanov's avatar
Vadim Galizyanov committed
    /**
     * Flatten a multi-dimensional associative array with dots.
     * @param array $array
     * @param $prepend
     * @return array
     */
    public static function dot(array $array, $prepend = ''): array
Vadim Galizyanov's avatar
Vadim Galizyanov committed
        $results = [];
Vadim Galizyanov's avatar
Vadim Galizyanov committed
        foreach ($array as $key => $value) {
            if (is_array($value) && ! empty($value)) {
                $results = array_merge($results, static::dot($value, $prepend.$key.'.'));
            } else {
                $results[$prepend.$key] = $value;
Vadim Galizyanov's avatar
Vadim Galizyanov committed

        return $results;