显示数组中的每个项目而不使用循环[关闭]

Hi i have this certain php function. But i cannot figured it out how to output this one. This is the question // Given an array, display each item in the array without using a loop. (Do not use built in functions to do this, like PHP's print_r; use a recursive function to implement) and this is the code

<?php
  function print_array(array $input)
  {
  }
?>

can someone share ideas on this? Any help is muchly appreciated.

you can use implode

$your_array = array("abc", "5", "xyz")

$text  = implode(" ", $your_array); // implode with space you can use any other on this place

echo $text;

OUTPUT : abc 5 xyz

FUNCTION :

function print_array($your_array)
{
   $text  = implode(" ", $your_array); // implode with space you can use any other on this place

    echo $text;
}

Recusive Method :

but only used when the key of the array is numeric starting with 0, 1, 2 ....

print_array($your_array);

function print_array($your_array, $index=0)
{   
    if(isset($your_array[$index]))
    {
        echo $your_array[$index]; 
        $index+=1;
        print_array($your_array, $index)
    }   
}