Answers for "array_walk_recursive get return value"

0

array_walk_recursive get return value

Flatten multidimensional associative array to array

function flatten(array $array, $prefix="") {
    $result = Array();
    array_walk($array, function ($value, $key) use ($array, $prefix, &$result) {
        $path = $prefix ? "$prefix.$key" : $key;
        if (is_array($value)) {
            $result = array_merge($result, flatten($value, $path));
        } else {
            $result[$path] = $value;
        }
    });

    return $result;
}

print_r(flatten($arrr));

from site:
https://stackoverflow.com/questions/39071537/array-walk-recursive-to-return-array-name-rather-than-index-number
Posted by: Guest on October-29-2020

Code answers related to "array_walk_recursive get return value"

Browse Popular Code Answers by Language