Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 1423 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Loop syntax in Php.

Thread title: Loop syntax in Php.
Closed Thread    
    Thread tools Search this thread Display Modes  
06-16-2008, 12:40 PM
#1
alisha is offline alisha
Status: Junior Member
Join date: Jun 2008
Location: India
Expertise:
Software:
 
Posts: 43
iTrader: 0 / 0%
 

alisha is on a distinguished road

  Old  Loop syntax in Php.

please tell the syntax of loop in php.

06-16-2008, 01:03 PM
#2
Salathe is offline Salathe
Salathe's Avatar
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
 
Posts: 3,820
iTrader: 25 / 100%
 

Salathe will become famous soon enough

Send a message via MSN to Salathe

  Old

There are a number of looping constructs available within PHP and without much of a prompt in the first post we can't be very specific in helping you. However here are some starting points which might be useful:
  • while
    while (condition) { statements }
  • do-while
    do { statements } while (condition)
  • for
    for (start; loop_start; loop_end) { statements }
  • foreach
    foreach (items as item) { statements }

06-16-2008, 10:49 PM
#3
Jme is offline Jme
Status: I'm new around here
Join date: Apr 2008
Location:
Expertise:
Software:
 
Posts: 12
iTrader: 0 / 0%
 

Jme is on a distinguished road

  Old

Basically what was said above but for instance if you wanted to write out a 5x table it'd be something like..

PHP Code:
for($i=1;$i<11;i++)
{
echo 
"5 x " $i " = " 5*$i "<br />";
}
//For loop

$i 1;
while(
$i<11)
{
echo 
"5 x " $i " = " 5*$i "<br />";
$i++;
}
//While Loop 
Thats basically it, same as javascript and most other languages.

06-20-2008, 08:50 PM
#4
justin00 is offline justin00
Status: I'm new around here
Join date: Jun 2008
Location: localhost
Expertise:
Software:
 
Posts: 5
iTrader: 0 / 0%
 

justin00 is on a distinguished road

Send a message via MSN to justin00

  Old

Another simple demo, this loop will run 10 times

$i = 0;
while($i < 10){
echo($i);
++$i;
}

You may notice I used ++$i, instead of $i++

Based on benchmarks ++$i is slightly faster

06-25-2008, 11:19 AM
#5
alisha is offline alisha
Status: Junior Member
Join date: Jun 2008
Location: India
Expertise:
Software:
 
Posts: 43
iTrader: 0 / 0%
 

alisha is on a distinguished road

  Old

thanks for your reply.
please tell about the applications used in PHP.

06-25-2008, 11:22 AM
#6
alisha is offline alisha
Status: Junior Member
Join date: Jun 2008
Location: India
Expertise:
Software:
 
Posts: 43
iTrader: 0 / 0%
 

alisha is on a distinguished road

  Old

what is the b/w ++$i and $i++?

06-25-2008, 12:58 PM
#7
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,894
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

Putting the ++ after returns the variable then increments it, having the ++ before increments it then returns the variable.

Meaning if you echo $a++, it will display $a then add it to one after is has passed it value. If you display ++$a, it will show the value of $a added by one.

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed