I am new to the world of coding as well as PHP and am wondering how I can use return when looping. For example I would like to return/display 1-10 however not use echo.
$start = 1;
$end = 11;
for($start; $start < $end; $start=$start+1) {
echo $start; //how can I use return?
}
Well,
returnwill exit the function, so if you putreturnin a loop, the loop will only do one iteration (until thereturnstatement).You can collect all the values in an array and return the array:
That said, a function generating consecutive numbers already exists:
range().