fork(1) download
  1. <?php
  2.  
  3. function nested_array($arr, $i, $size)
  4. {
  5. if ($i == ($size-1))
  6. {
  7. return array($arr[$i] => ".");
  8. }
  9.  
  10. return array($arr[$i] => nested_array($arr,($i+1),$size));
  11. }
  12.  
  13. print_r(nested_array(array("I", "need", "this", "to", "be", "nested"),0,6));
  14.  
Success #stdin #stdout 0.01s 24400KB
stdin
Standard input is empty
stdout
Array
(
    [I] => Array
        (
            [need] => Array
                (
                    [this] => Array
                        (
                            [to] => Array
                                (
                                    [be] => Array
                                        (
                                            [nested] => .
                                        )

                                )

                        )

                )

        )

)