homepage Welcome to WebmasterWorld Guest from 23.22.29.137
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Grab last variable from a While Loop?
Schoolbag




msg:1261790
 4:40 pm on Mar 3, 2004 (gmt 0)

Hi,

Im currently getting info from a loop like this:

###start###

$numberofchildren = "3";

$current = 0;
while ($current < $numberofchildren) {
++$current;

$a="a";
$b="a";

if ($a=="$b") {
echo "test$current ";
}
}

###end###

This will Print: "test1 test2 test3"

How can I get it to ONLY print "test3"?

Any help is appreciated.

 

lorax




msg:1261791
 4:59 pm on Mar 3, 2004 (gmt 0)

Um... why are you using a loop if that's all you want to do? There must be some parameters other than what you've given us and they'll most likely influence our answers. ;)

Schoolbag




msg:1261792
 5:03 pm on Mar 3, 2004 (gmt 0)

The actual code is much more complicated. This may help, the $numberofchildren variable can vary, it can be anything from 1 - 12.

The code is a sample that actually works.

So how can I just get back the last variable info?

thanks!

webdevjim




msg:1261793
 5:15 pm on Mar 3, 2004 (gmt 0)

Hi,
Just put an if statement in the loop

if ($current == $noofchildren) then do something

lorax




msg:1261794
 5:58 pm on Mar 3, 2004 (gmt 0)

>> Just put an if statement in the loop

Yup, that should work.

jonknee




msg:1261795
 7:45 pm on Mar 3, 2004 (gmt 0)

Or you could just do the printing outside the while loop--it will naturally have the last value of the loop.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved