3v4l.org

run code in 300+ PHP versions simultaneously
<?php $keys = [ 'my', 'name', 'is', 'Rafael' ]; $value = 'value'; $result = array_reduce( array_reverse( $keys ), function ( $c, $i ) use ( $value ) { return [ $i => ( is_null( $c ) ? $value : $c ) ]; } ); print_r( $result ); // или $result = array_reduce( array_reverse( $keys ), fn( $c, $i ) => [ $i => $c ?? $value ] ); print_r( $result );

preferences:
48.89 ms | 402 KiB | 5 Q