php - how to use explode for an array of objects

Solution:

you can use laravel data_get helper:

data_get($value2, $value2['champ'])

Answer

Solution:

To nest the $segments of the string starting with the innermost item of the result, we have to array_reverse() the $segments so we can loop over it and wrap each iteration's result with another array level in the next iteration until we looped through the whole $segments array.

$exploded = array_reduce(array_reverse(explode('.', $value2['champ'])), function($res, $segment) {
    return [ $segment => $res ];
}, []);

Source