Click here to Skip to main content
14,927,639 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi All,

i had tried diff loops all works but i need to display same results out side the loops any one help me

//while loop
$x = 1;
while ($x <= 9)
    $numZero = 1 - strlen($x);
    echo $x;
	echo '';

//for loop
echo $i.'';
Updated 23-Oct-14 20:29pm
Maciej Los 24-Oct-14 2:09am
What would you like to display outside the loop?
Use echo command outside the loop. That's all!
Arun-23 24-Oct-14 2:11am
i had used but it displays only last value
Maciej Los 24-Oct-14 2:17am
Use 'Reply' widget to post comment as a reply.
Do you want to display all values?
Arun-23 24-Oct-14 2:33am
yes same has inside the loop
Maciej Los 24-Oct-14 2:45am
Have you seen my answer?
Arun-23 24-Oct-14 3:01am
thanks for ur help :)
Maciej Los 24-Oct-14 3:02am
You're very welcome ;)

1 solution

You need to declare variable, which you can use inside loop to build string.

Please, have a look here:[^][^]

To convert integer to string, use:
$str = (string) $int;

$str = '';
//for loop
$str .= (string)$i;
echo $str;

Note: i'm not php programmer ;)

Good luck!
5ed. Being not a PHP programmer is itself a good characteristic. :-)
Maciej Los 24-Oct-14 3:24am
Thank you very much, Sergey ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900