ShaolinF Posted January 4, 2009 Share Posted January 4, 2009 Hi Guys I have a for loop which prints out 1 to 10. See code below: for ($i=10;i<10;i++){ echo $i; } It prints out as follows: 1 2 3 4 ..... How can I code it so that the html doesnt print out each integer on a seperate line but rather repaces the first value ? For example: The script outputs "1", when the loop runs the second time it deletes the "1" and replaces it with "2". Link to comment https://forums.phpfreaks.com/topic/139431-printing-data/ Share on other sites More sharing options...
ohdang888 Posted January 4, 2009 Share Posted January 4, 2009 Once you echo something, you can't go back and delete it without javascript... my suggestion, if the number you want varies (sometimes 1, sometimes 10, etc), put it all into an array, and use array functions to find the value you want Link to comment https://forums.phpfreaks.com/topic/139431-printing-data/#findComment-729357 Share on other sites More sharing options...
priti Posted January 4, 2009 Share Posted January 4, 2009 May i ask what is the aim behind it ??? for ($i=10;i<10;i++){ $last_run_value= $i; } echo $last_run_value; this will print the last value. if the loop run for 5 times it will print 5 if 3 then 3... but i am curious to know why you want so ?? Thanks Link to comment https://forums.phpfreaks.com/topic/139431-printing-data/#findComment-729359 Share on other sites More sharing options...
ShaolinF Posted January 4, 2009 Author Share Posted January 4, 2009 well if I have 1000s of integers to loop through then its going to slow the browser down if it prints out each integer on its own line. Link to comment https://forums.phpfreaks.com/topic/139431-printing-data/#findComment-729362 Share on other sites More sharing options...
ohdang888 Posted January 4, 2009 Share Posted January 4, 2009 well if I have 1000s of integers to loop through then its going to slow the browser down if it prints out each integer on its own line. no, the line breaks won't matter, at all, that's static html. Any loop going hrough thousands of times will slow down the process, not matter if its echoing or not. Link to comment https://forums.phpfreaks.com/topic/139431-printing-data/#findComment-729369 Share on other sites More sharing options...
priti Posted January 5, 2009 Share Posted January 5, 2009 well if I have 1000s of integers to loop through then its going to slow the browser down if it prints out each integer on its own line. but ... okie suppose you are searching 101 in those 1000 integer then you will loop to 1000 integer ????? NO!! because when your script spot the 101 value it should break the loop and come out ... it will save time also. But still if u want to add simple loop to delay then you don't need to print and if you are have such a big loop then you have to keep some check else it will slow down the response. Thanks Link to comment https://forums.phpfreaks.com/topic/139431-printing-data/#findComment-729777 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.