fork download
  1. <?php
  2.  
  3. $array = [5, 6, 7, 8];
  4.  
  5. for ($i = count($array) - 1; $i >= 0; $i--) {
  6. $result = empty($result) ? [$array[$i]] : [$array[$i], $result];
  7. }
  8.  
  9. var_export($result);
  10.  
Success #stdin #stdout 0.02s 24292KB
stdin
Standard input is empty
stdout
array (
  0 => 5,
  1 => 
  array (
    0 => 6,
    1 => 
    array (
      0 => 7,
      1 => 
      array (
        0 => 8,
      ),
    ),
  ),
)