PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php echo '' ?? 'hello'; function format(string $rawPath): string { preg_match_all('/(^[^\[;^\]]+)|(\[[^[]+])/', $rawPath, $matches); $groups = reset($matches); if ($groups === false) { $groups = []; } return array_reduce( $groups, static fn (string $path, string $part): string => ( $path . '[' . trim($part, '[ ]') . ']' ), trim((array_shift($groups) ?? ''), '[]') ); } echo format('[hello][0][world]');
Show:  
Copy Clear