Can anyone teach me how to print "Hello World" 100 times without using the loop such as do, for, while, and foreach.
Thanks...

how?

<?php

    function printvalue($val)
    {
         if($val>1)
               printvalue($val-1);
          echo $val."<br>";
         return;
    }

    printvalue(100);
?>

as far as i know you have to loop, thats exactly what repeating something is.

urtrivedi has done a good example of recursion, its basically long hand of doing what while($i > 1) does.

If you don't want a loop type it out 100 times

Member Avatar for diafol

I'd love to know the point of all this :)

Why decade?

How about something simple like:

echo str_repeat('Hello World ', 100);

R.

commented: Simple but effective. Nice. +14
commented: Indeed, like Python print 100*'Hello World ', only I do not know PHP deeply enough to suggest. +12

You can also do it this way...C++ style... The $z is rolling in its own grease a 100 times ..

  <?php
  call_user_func( $x = function( $yx, $z =1 ) {
echo (string)("Hello World <br/>"), $yx[floor($z/100)]($yx, ++$z);
}, array( $x, function(){} ));

?>

Or, you could use:

echo implode(' ', array_fill(0, 100, 'Hello World'));

R

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.