Add information to a variable after loop?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
patj
Forum Newbie
Posts: 2
Joined: Mon Sep 27, 2010 5:37 pm

Add information to a variable after loop?

Post by patj »

Is there a way to add new data to a variable after each passing through a loop? After the original data that is. Or is there some other way to make this script work? This is what i want to do:

If the input is 2, the output should be:
x
xx
if it is 3 it should output:
x
xx
xxx
This is what i got so far...

Code: Select all

<?php

$input = 3;
$i = 1;
$x = "x";

while ($i <= $input) {

echo $x."<br>";

$i++;

}

?>
Thanks!
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: Add information to a variable after loop?

Post by DigitalMind »

Code: Select all

$input = 5;
$x = 'x';
for ($i = 0; $i < $input; $i++) {
    echo $x.'<br>';
    $x .= 'x';
}
patj
Forum Newbie
Posts: 2
Joined: Mon Sep 27, 2010 5:37 pm

Re: Add information to a variable after loop?

Post by patj »

DigitalMind wrote:

Code: Select all

$input = 5;
$x = 'x';
for ($i = 0; $i < $input; $i++) {
    echo $x.'<br>';
    $x .= 'x';
}
Thanks a lot!
Post Reply