3v4l.org

run code in 300+ PHP versions simultaneously
<?php $structure = [ "a", "b" => [ "b1", "b2" => [ "b21", "b22" ] ] ]; $data = ['A', 'B1', 'B21', 'B22']; $filled = 0; array_walk_recursive ($structure, function (&$val) { global $filled; global $data; $val = array( $val => $data[ $filled ] ); $filled++; }); print_r( $structure );

preferences:
29.2 ms | 402 KiB | 5 Q