3v4l.org

run code in 500+ PHP versions simultaneously
<?php $user = [ 'profile' => [ 'authkey' => '', 'publickey' => '', 'status' => 19 ], 'setup' => [ 'profile' => false, 'contact' => false, 'payments' => false, 'subscription' => false ], 'paygateway' => [ 'paypal' => [ 'publickey' =>'', 'secretkey' => '', 'testarray' => [ 'key1' => 'value1', 'key2' => 'value2', 'key3' => [ 'key4' => 'level4' ] ], 'webhookid' => '' ], 'stripe' => [ 'publickey' => '', 'secretkey' => '' ] ] ]; function buildKeyPath(array $array, string $path): array { $result = []; foreach ($array as $key => $value) { if (is_array($value)) { array_push($result, ...buildKeyPath($value, "{$path}[$key]")); } else { $result[] = "{$path}[$key]"; } } return $result; } foreach ($user as $k => &$v) { $v = buildKeyPath($v, "[$k]"); } var_export($user);
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
array ( 'profile' => array ( 0 => '[profile][authkey]', 1 => '[profile][publickey]', 2 => '[profile][status]', ), 'setup' => array ( 0 => '[setup][profile]', 1 => '[setup][contact]', 2 => '[setup][payments]', 3 => '[setup][subscription]', ), 'paygateway' => array ( 0 => '[paygateway][paypal][publickey]', 1 => '[paygateway][paypal][secretkey]', 2 => '[paygateway][paypal][testarray][key1]', 3 => '[paygateway][paypal][testarray][key2]', 4 => '[paygateway][paypal][testarray][key3][key4]', 5 => '[paygateway][paypal][webhookid]', 6 => '[paygateway][stripe][publickey]', 7 => '[paygateway][stripe][secretkey]', ), )

preferences:
91.08 ms | 1366 KiB | 4 Q