Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Нужно написать код, который из массива выведет то что приведено ниже в комментарии.
- */
- $x = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
- function formatArray($x)
- {
- $foo = function ($x) use (&$foo) {
- if (prev($x)) {
- $acc[current($x)] = $foo($x);
- return $acc;
- } else {
- return '';
- }
- };
- $result = [];
- $result[end($x)] = $foo($x);
- return $result;
- }
- echo '<pre>';
- print_r(formatArray($x));
- echo '</pre>';
- /*
- print_r($x) - должен выводить это:
- Array
- (
- [h] => Array
- (
- [g] => Array
- (
- [f] => Array
- (
- [e] => Array
- (
- [d] => Array
- (
- [c] => Array
- (
- [b] => Array
- (
- [a] =>
- )
- )
- )
- )
- )
- )
- )
- );*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement