0

let's get the output of a loop in a variable, i am trying to return data in a for loop. Here is the code:

<?php
for($i=0,$j=0; $i<=10, $j<=10; $i++,$j++){
    $data = "$i and $j<br>";
    return $data;
}
echo $data;
?>

Here is the code http://codepad.org/qqnGdjS7
so, how return data in php for loop, so there is ways to use loop data outside of the loop!

2 Answers 2

1

Try with:

$data = '';
for($i=0,$j=0; $i<=10, $j<=10; $i++,$j++){
    $data .= "$i and $j<br/>";
}
echo $data;
Sign up to request clarification or add additional context in comments.

Comments

1

is it really the loop you want ? 1 1, 2 2, 3 3 ? to have 1 1, 1 2, 1 3, ... do:

$data = '';
for($i=0; $i<=10; $i++){
    for($j=0; $j<=10; $j++){
        $data .= "$i and $j<br/>";
    }
}
echo $data;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.