PDA

View Full Version : Blocks and return value


Jerppu
07-21-2011, 03:44 PM
Hi. How could I get results of following loop to side block on my forum (php/html)

So output 5 times $description :


$limit = 5;
for($x=0;$x<$limit;$x++) {
...random code...
$description = $feed[$x]['desc'];
...random code...
}


Instruction says:
$my_output = 'Hello, world.';
return $my_output;

But if I add "return $description;", I get only one output cause "return" immediately ends execution of the code.

nhawk
07-21-2011, 04:02 PM
This will return all 5 descriptions in one shot..

$limit = 5;
for($x=0;$x<$limit;$x++) {
...random code...
$description .= $feed[$x]['desc'] . '<br />';
...random code...
}
return $description;

--------------- Added 1311268112 at 1311268112 ---------------

Or $description can be returned as an array..

$limit = 5;
for($x=0;$x<$limit;$x++) {
...random code...
$description[] = $feed[$x]['desc'] .'<br />';
...random code...
}
return $description;

Jerppu
07-21-2011, 04:14 PM
Thank you !