Format simple array in multidimensional
A reference variable will save you from that wicked code bloat!
You can make iterative calls of this Stack Overflow answer from 2012.
Code: (Demo)
function assignArrayByPath(&amp;$arr, $path, $value, $separator = '_') {
    $keys = explode($separator, $path);
    foreach ($keys as $key) {
        $arr = &amp;$arr[$key];
    }
    $arr = $value;
}
    
foreach ($array as $key =&gt; $value) {
    unset($array[$key]);
    assignArrayByPath($array, $key, $value);
}
var_export($array);


Or boil it down to this: (Demo)
function assignArrayByPath(&amp;$result, $path, $value) {
    foreach (explode('_', $path) as $key) {
        $result = &amp;$result[$key];
    }
    $result = $value;
}

$result = [];
foreach ($array as $key =&gt; $value) {
    assignArrayByPath($result, $key, $value);
}
var_export($result);

This technique will require that you build logical (non-monkey-wrenching) paths as keys.  I mean:

If after 'max_size_photo' =&gt; 8000, you declare 'max' =&gt; 10000, then you will get an error.
If after 'max_size_photo' =&gt; 8000, you declare 'max_size' =&gt; 10000, then you will erase the previously expanded (deeper) elements from the output array.


p.s. You can also write it without any custom functions by nesting the loops so long as you maintain the technique of using a reference variable inside of a reference variable.  Trippy, right?
Code: (Demo)
$result = [];
foreach ($array as $path =&gt; $value) {
    $ref = &amp;$result;
    foreach (explode('_', $path) as $key) {
        $ref = &amp;$ref[$key];
    }
    $ref = $value;
}
var_export($result);