PHPize Online / SQLize Online

A A A
Share   Donate   Blog   Popular
Copy Format Clear
Copy
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