You are here: DEVPPL Forum Programming PHP and MySQL Forum Script-archive
NOTIFICATIONS
54.099
MEMBERS
15.693
TOPICS
62.271
POSTS
  562
FLASH GAMES
7.740
TUTORIALS
 

Login

E-mail:
Password:

For Loop Example

Share your completed scripts.
0

Loading

For Loop Example

Postby HotNoob » Tue Sep 21, 2010 10:56 pm

This is just a quick bit to show how to use a for loop in PHP

Code: Select all
<?php
$string = "Hello World";
$length = strlen($string);

for($i = 0; $i < $length; $i++)
{
    echo $string[$i].'<br />';
}

?>


The For Loop Syntax.
It is actually really simple
Code: Select all
for(VARIABLE DECLARATION; CONDITION; INCREMENT)

What happens during the code execution is that at the beginning, it runs the variable declaration code first, then it checks the condition statement( like an if statement), and if it is true, than it runs through the block of code(whats in between the brackets), and finally it calls the increment code.

Unfortunately, in PHP the for loop is LESS efficient than the foreach loop, which is the complete opposite when compared to most programming languages, such as c, c++, c#, and so on.

well i hope that shows you guys some of the basics :D
HotNoob
 
Reputation: 0
Posts: 169
Joined: Sun May 02, 2010 2:38 am
Highscores: 0
Arcade winning challenges: 0

For Loop Example - Sponsored results

Sponsored results

Login to get rid of ads

 

^ Back to Top