ȨÀ¸·Î ȨÀ¸·Î | ¹«·áȸ¿ø°¡ÀÔ | ¾ÆÀ̵ð/ºñ¹øÃ£±â | Áñ°Üã±â
ÃßõÀ½¾Ç¹æ¼Û¸ÞÀÎȨ1´ë1»ó´ãÀ½¾Ç¹æ¼ÛûÃë
okTrot(±¸µ¶ÇØÁÖ¼¼¿ä)
ÀüÅë°¡¿ä(±¸µ¶ÇØÁÖ¼¼¿ä)
»Í¦¾Æ°¡¾¾(±¸µ¶ÇØÁÖ¼¼¿ä)
¾Æ¸®¶û°¡¿ä(±¸µ¶ÇØÁÖ¼¼¿ä)
À½¾Ç°¡»ç °Ë»ö
¿Â¶óÀ̺꽺Åä¾î(¾Û´Ù¿î·Îµå)
¿Â¶óÀ̺ê(¹æ¼Ûµî·Ï¹×ûÃë)
ºñµð¿À º£½ºÆ® 50
±Ý¿µ³ë·¡¹æ
TJ³ë·¡¹æ
À¯Æ©ºê µ¿¿µ»ó ´Ù¿î·Îµå
POP Player
½Å³ª´Â °í½ºÅé
ÄÄÇ»ÅÍ ¿À¸ñ
ÀÛÀº À½¾Ç´Ù¹æ
¿î.¿µ.ÀÚ.1´ë1.»ó´ã
FAQ¡¬Áö¿ø.ÇÁ·Î±×·¥
Q&A¡¬°í.°´.Áö.¿ø

ÀÚµ¿·¯½Ã À¥Ç÷¹À̾î½Åû

º¸¾È¡ñ¼­¹ö¡ñÄíŰ
À©µµ¿ì¡ñÇÁ·¹ÀÓ
À̹ÌÁö¡ñ¹è°æ
½Ã°£¡ñ´Þ·Â¡ñ°è»ê
»óŹ١ñŸÀÌÆ²¹Ù
À½¾Ç¡ñ¿µ»ó
Æû¡ñÀü¼Û¡ñÅ×À̺í
Űº¸µå¡ñ¸¶¿ì½º
È¿°ú¡ñ¸µÅ©¡ñ¸Þ´º
Script¡ñphp
±âŸ
PHP °­ÁÂ
À©µµ¿ì°ü·ÃÆÁ
À¥°ü·ÃÆÁ
ȨÆäÀÌÁöÁ¦ÀÛÆÁ
±âº»°­ÁÂ
·¹Áö½ºÆ®¸®
À©µµ¿ì¼­¹ö
¸®´ª½º¼­¹ö
Android
PHP for ¹®
7³â Àü
for·çÇÁ´Â PHP¿¡¼­ Á¦ÀÏ º¹ÀâÇÑ ·çÇÁÀÌ´Ù. C¿Í ¶È°°Àº ¹æ½ÄÀ¸·Î µ¿ÀÛÇÑ´Ù. for·çÇÁÀÇ ¹®¹ýÀº ´ÙÀ½°ú °°´Ù:

for (expr1; expr2; expr3)
    statement

ù¹øÂ° Ç¥Çö½Ä(expr1)Àº ·çÇÁÀÇ ½ÃÀÛ¿¡¼­ ¹Ù·Î Á¶°Ç¾øÀÌ Æò°¡µÈ´Ù (¼öÇàµÈ´Ù).

°¢ ¹Ýº¹(iteration)ÀÇ ½ÃÀۺκп¡¼­ expr2ÀÌ Æò °¡µÈ´Ù. ÀÌ Ç¥Çö½ÄÀÌ TRUEÀÌ¸é ·çÇÁ´Â °è¼ÓµÇ°í ³»Æ÷µÈ ±¸¹®(µé)ÀÌ ¼öÇàµÈ´Ù. FALSEÀ̸é, ·çÇÁ ¼öÇàÀ» ¸ØÃá´Ù.

expr3Ç¥Çö½ÄÀº °¢ ¹Ýº¹ÀÇ ³¡ºÎºÐ¿¡¼­ Æò°¡µÈ´Ù (¼öÇàµÈ´Ù).

°¢ Ç¥ÇöÀº ºñ¾îÀְųª ÄÞ¸¶·Î ±¸ºÐÇÑ ¿©·¯ Ç¥ÇöÀ» °¡Áú ¼ö ÀÖ½À´Ï´Ù. expr2¿¡¼­, ÄÞ¸¶·Î ±¸ºÐÇÑ Ç¥ÇöÀº ¸ðµÎ Æò°¡µÇÁö¸¸ °á°ú´Â ¸¶Áö¸· ºÎºÐ¿¡¼­¸¸ °¡Á®¿É´Ï´Ù. expr2ÀÌ ºñ¾îÀÖ´Ù´Â °ÍÀº ·çÇÁ°¡ ¹«Á¦ÇÑ ¼öÇàµÇ¾î¾ß ÇÑ´Ù´Â °ÍÀ» ÀǹÌÇÑ´Ù (PHP´Â Có·³ TRUE·Î ÀνÄ) ÀÌ·± ±â¹ýÀº »ý°¢Ã³·³ ÇÊ¿ä¾øÁö´Â ¾Ê´Ù. ¿Ö³Ä Çϸé Á¾Á¾ for¹®ÀÇ Ç¥Çö½Ä ´ë½Å¿¡ break¹®À¸·Î ·çÇÁ¸¦ ³¡³¾ Çʿ䰡 Àֱ⠶§¹®ÀÌ´Ù.

´ÙÀ½ ¿¹Á¦ ÄÚµåµéÀ» º¸¼¼¿ä. ÀÌ ÄÚµå ¸ðµÎ 1ºÎÅÍ 10±îÁöÀÇ ¼ýÀÚ¸¦ Ãâ·ÂÇÑ´Ù:

<?php
/* ¿¹Á¦ 1 */

for ($i = 1; $i <= 10; $i++) {
    echo $i;
}

/* ¿¹Á¦ 2 */

for ($i = 1; ; $i++) {
    if ($i > 10) {
        break;
    }
    echo $i;
}

/* ¿¹Á¦ 3 */

$i = 1;
for (; ; ) {
    if ($i > 10) {
        break;
    }
    echo $i;
    $i++;
}

/* ¿¹Á¦ 4 */

for ($i = 1, $j = 0; $i <= 10; $j += 1, print $i, $i++);
?>

¹°·Ð, ù¹øÂ° ¿¹Á¦(ȤÀº ³×¹øÂ°) Äڵ尡 °¡Àå ÁÁÀº ¹æ¹ýÀÌ´Ù. ±×·¯³ª for·çÇÁ¿¡¼­ ºó Ç¥Çö½ÄÀ» »ç¿ëÇØ¾ß ÇÏ´Â °æ¿ìµµ ºÎµúÈ÷°Ô µÉ°ÍÀÌ´Ù.

PHP´Â for·çÇÁ¿¡ ´ëÇÑ ´ëü "Äݸ¥ ¹®¹ý"À» Áö¿øÇÑ´Ù.

for (expr1; expr2; expr3):
    statement
    ...
endfor;

¸¹Àº »ç¿ëÀÚ°¡ ¾Æ·¡ ¿¹Á¦Ã³·³ ¹è¿­À» Ž»öÇÕ´Ï´Ù.


<?php
/*
* ÀÌ ¹è¿­Àº ·çÇÁ¸¦ µµ´Â µ¿¾È
* º¯°æÇÒ µ¥ÀÌÅ͸¦ °¡Áö°í ÀÖ½À´Ï´Ù.
*/
$people = Array(
        Array('name' => 'Kalle', 'salt' => 856412),
        Array('name' => 'Pierre', 'salt' => 215863),
        );

for($i = 0; $i < sizeof($people); ++$i)
{
    $people[$i]['salt'] = rand(000000, 999999);
}
?>

¹®Á¦´Â µÎ¹øÂ° Ç¥Çö½ÄÀÔ´Ï´Ù. ÀÌ ÄÚµå´Â ¸Å ½ÇÇึ´Ù ¹è¿­ÀÇ Å©±â¸¦ °è»êÇϱ⠶§¹®¿¡ ´À·ÁÁý´Ï´Ù. Å©±â´Â º¯ÇÏÁö ¾Ê±â ¶§¹®¿¡, Å©±â¸¦ ÀúÀåÇÏ´Â Áß°£ º¯¼ö¸¦ »ç¿ëÇÏ¿© ·çÇÁ¸¦ µ¹¸®µµ·Ï ÃÖÀûÈ­ ÇÒ ¼ö ÀÖ½À´Ï´Ù. ¾Æ·¡ ¿¹Á¦°¡ º¸¿©ÁÝ´Ï´Ù:


<?php
$people = Array(
        Array('name' => 'Kalle', 'salt' => 856412),
        Array('name' => 'Pierre', 'salt' => 215863),
        );

for($i = 0, $size = sizeof($people); $i < $size; ++$i)
{
    $people[$i]['salt'] = rand(000000, 999999);
}
?>



foreach do-while
--------------------------------------------------------------------------------
Last updated: Fri, 24 Jul 2009
  
  add a note User Contributed Notes
for
kanirockz at gmail dot com
21-Mar-2010 07:49
Here is another simple example for " for loops"

<?php

$text="Welcome to PHP";
$searchchar="e";
$count="0"; //zero

for($i="0"; $i<strlen($text); $i=$i+1){
    
    if(substr($text,$i,1)==$searchchar){
    
       $count=$count+1;
    }

}

echo $count

?>

this will be count how many "e" characters in that text (Welcome to PHP)
kanirockz at gmail dot com
21-Mar-2010 07:48
Here is another simple example for " for loops"

<?php

$text="Welcome to PHP";
$searchchar="e";
$count="0"; //zero

for($i="0"; $i<strlen($text); $i=$i+1){
    
    if(substr($text,$i,1)==$searchchar){
    
       $count=$count+1;
    }

}

echo $count

?>

this will be count how many "e" characters in that text (Welcome to PHP)
Steven
11-Jan-2009 06:50
Alternating form rows:

<?php

$rows = 4;

echo '<table><tr>';

for($i = 0; $i < 10; $i++){
    echo '<td>' . $i . '</td>';
    if(($i + 1) % $rows == 0){
        echo '</tr><tr>';
    }
}

echo '</tr></table>';

?>

Changing $rows will change how many columns are in a row.
dkimbel13 at gmail dot com
07-Jan-2009 11:41
Just a note on looping through an array using the for() loop.

with the array...
<?php $array = array("value1","value2","value3"); ?>

then...
<?php
for(reset($array),current($array),next($array){
    echo("Element ".key($array)." contains ".current($array)."<br/>";
}
?>

is the equivalent of...
<?php
for($i=0;$i<count($array);$i++){
    echo("Element $i contains $array[$i]<br/>");
}
?>

I don't know if there is any advantage, just thought I would mention it.
http://badluck.tv
24-Mar-2008 01:05
Nested For Loop with the same iterator as the parent.
(Well formatted so the resulting code is clean when executed).
Useful for outputting a data array into a table, ie. images.

<?php
//Dummy data
$data = array(73,74,75,76,78,79,80,81,82,83,84,85,86,87);

//Our 'stepping' variable
$g = 0;

//Our rowcount
$rowcount = 0;

echo "<table cellspacing='0'>\r";
    for ($i=0; $i<count($data); ) {

        $rowcount++;
        echo "    <tr>\r"; //New row

        $g = $i + 3; //Set our nested limit
        for( ; $i<$g; $i++) { //nested for loop

            if (!isset($data[$i])) { //Allow us to break on incomplete rows
                break;
            }

            echo "        <td style='border: 1px #000 solid;'>\r"; //Out put a cell
            echo "            <p>Row $rowcount <br/> Cell: $i <br/> Data: $data[$i]</p>\r";
            echo "        </td>\r";
        }

        echo "    </tr> \r"; //End New Row
    }

echo "</table>\r";?>
eduardofleury at uol dot com dot br
14-Jun-2007 01:18
<?php
//this is a different way to use the 'for'
//Essa é uma maneira diferente de usar o 'for'
for($i = $x = $z = 1; $i <= 10;$i++,$x+=2,$z=&$p){
    
    $p = $i + $x;
    
    print "\$i = $i , \$x = $x , \$z = $z <br />";
    
}

?>
lishevita at yahoo dot co (notcom) .uk
08-Sep-2006 07:33
On the combination problem again...

It seems to me like it would make more sense to go through systematically. That would take nested for loops, where each number was put through all of it's potentials sequentially.

The following would give you all of the potential combinations of a four-digit decimal combination, printed in a comma delimited format:

<?php
for($a=0;$a<10;$a++){
    for($b=0;$b<10;$b++){
          for($c=0;$c<10;$c++){
              for($d=0;$d<10;$d++){
                echo $a.$b.$c.$d.", ";
              }
           }
      }
}
?>

Of course, if you know that the numbers you had used were in a smaller subset, you could just plunk your possible numbers into arrays $a, $b, $c, and $d and then do nested foreach loops as above.

- Elizabeth
JustinB at harvest dot org
04-Aug-2005 11:23
For those who are having issues with needing to evaluate multiple items in expression two, please note that it cannot be chained like expressions one and three can.  Although many have stated this fact, most have not stated that there is still a way to do this:

<?php
for($i = 0, $x = $nums['x_val'], $n = 15; ($i < 23 && $number != 24); $i++, $x + 5;) {
    // Do Something with All Those Fun Numbers
}
?>
user at host dot com
19-Apr-2004 10:53
Also acceptable:

<?php
  for($letter = ord('a'); $letter <= ord('z'); $letter++)
   print chr($letter);
?>
bishop
17-Jul-2003 08:23
If you're already using the fastest algorithms you can find (on the order of O(1), O(n), or O(n log n)), and you're still worried about loop speed, unroll your loops using e.g., Duff's Device:

<?php
$n = $ITERATIONS % 8;
while ($n--) $val++;
$n = (int)($ITERATIONS / 8);
while ($n--) {
    $val++;
    $val++;
    $val++;
    $val++;
    $val++;
    $val++;
    $val++;
    $val++;
}
?>

(This is a modified form of Duff's original device, because PHP doesn't understand the original's egregious syntax.)

That's algorithmically equivalent to the common form:

<?php
for ($i = 0; $i < $ITERATIONS; $i++) {
    $val++;
}
?>

$val++ can be whatever operation you need to perform ITERATIONS number of times.

On my box, with no users, average run time across 100 samples with ITERATIONS = 10000000 (10 million) is:
Duff version:       7.9857 s
Obvious version: 27.608 s
nzamani at cyberworldz dot de
18-Jun-2001 06:47
The point about the speed in loops is, that the middle and the last expression are executed EVERY time it loops.
So you should try to take everything that doesn't change out of the loop.
Often you use a function to check the maximum of times it should loop. Like here:

<?php
for ($i = 0; $i <= somewhat_calcMax(); $i++) {
  somewhat_doSomethingWith($i);
}
?>

Faster would be:

<?php
$maxI = somewhat_calcMax();
for ($i = 0; $i <= $maxI; $i++) {
  somewhat_doSomethingWith($i);
}
?>

And here a little trick:

<?php
$maxI = somewhat_calcMax();
for ($i = 0; $i <= $maxI; somewhat_doSomethingWith($i++)) ;
?>

The $i gets changed after the copy for the function (post-increment).
ÃßõÃßõ : 227 Ãßõ ¸ñ·Ï
¹øÈ£ Á¦¸ñ
3,014
 curl ÇÔ¼ö¸¦ ÀÌ¿ëÇÑ HTTP REFERER º¯°æ
3,013
 À©µµ¿ì10 ½Ã½ºÅÛ ÆÄÀÏ ¹× Dism °Ë»ç
3,012
 ÅؽºÆ® ÁٹٲÞ, ±ÛÀÚÀÚ¸£±â CSS
3,011
 jQuery Mobile¿¡¼­ À¯¿ëÇÑ ÄÚµå 10°¡Áö.
3,010
 [PHP] dirname()ÇÔ¼ö¿Í $_SERVER °ü·Ã »ó¼öµé
3,009
 [PHP] ÆÄÀÏ Å©±â, »çÀÌÁî ºÒ·¯¿À´Â ÇÔ¼ö, filesize()
3,008
 [jQuery] jQuery Quick API
3,007
 [ transition ] ¸µÅ© hover »ö»ó º¯È­ ¼Óµµ Á¶Àý
3,006
 PHP 5.3.0 ¿¡¼­ »ç¶óÁø ÇÔ¼öµé ´ëü
3,005
 ¾î¶² ÆÄÀϵéÀÌ include ³ª require µÇ¾ú´ÂÁö È®ÀÎÇÏ´Â ÇÔ¼ö(get_included_files)
3,004
 PHP ³¯Â¥ Çü½Ä ¹× °è»êÇϱâ(³¯Â¥ ´õÇÏ°í »©±â)
3,003
 jQuery Mobile¿¡¼­ À¯¿ëÇÑ ÄÚµå 10°¡Áö.
3,002
 °ªÀÌ ¹è¿­ ¾È¿¡ Á¸ÀçÇÏ´ÂÁö È®ÀÎÇÏ´Â in_arrayÇÔ¼ö
3,001
 »ç¿ëÀÚ°¡ À¥ºê¶ó¿ìÀú¿¡¼­ µÚ·Î°¡±â¸¦ ÇßÀ»¶§ °¨ÁöÇÏ´Â ¹æ¹ý
3,000
 [jQuery]¹öư Ȱ¼ºÈ­, ºñȰ¼ºÈ­
2,999
 jQuery show() / hide() / toggle() »ç¿ë¹ý
2,998
 jquery ¿©·¯°¡Áö À̺¥Æ®
2,997
 border-radius ¼Ó¼º
2,996
 ³×À̹ö ¿ÀÇÂAPI À½¼ºÇÕ¼º API »ç¿ëÇÏ´Â PHP »ùÇÃÄÚµå
2,995
 UTF8 ÇÑ±Û ÀÚ¸£±â..
2,994
 iconv ¿¡·¯ ¹ß»ý½Ã °è¼Ó ó¸®Çϱ⠿ɼÇ
2,993
 [PHP] ÇöÀç ÆäÀÌÁöÀÇ µµ¸ÞÀÎ , URL Á¤º¸ ¾Ë¾Æ³»±â.
2,992
 [PHP] ¸·°­ ±â´É ¹è¿­..
2,991
 [CSS] - Input clear `X ` ¹öư Á¦°Å ( IE, Chrome, Firefox )
2,990
 [Mobile] - ¸ð¹ÙÀÏÀ¥ Href ű׼Ӽºµé
2,989
 [JqueryMobile] - ÇöÀçÈ­¸éÀÇ °¡·Î¼¼·Î »çÀÌÁî ±¸Çϱâ
2,988
 [JqueryMobile] - È­¸éÀÇ °¡·Î, ¼¼·Î »çÀÌÁî ±¸ÇÏ´Â ¹æ¹ý
2,987
 jquery·Î °¡·Î ³ÐÀÌ(width), ¼¼·Î ³ôÀÌ(height) ÀÚµ¿ Á¶Àý
2,986
 iframe ³ôÀÌ jquery·Î ÀÚµ¿Á¶ÀýÇϱâ
2,985
 jQuery ¿À¸¥ÂÊ ¿µ¿ªÀÇ ³ôÀ̸¦ ¿ÞÂÊ ¿µ¿ªÀÇ ³ôÀÌ¿Í µ¿ÀÏÇÏ°Ô Çϱâ
2,984
 jquery¿¡¼­ Å×À̺í ¦¼ö, Ȧ¼ö ¹øÂ° TR ¹è°æ»ö º¯°æÇϱâ
2,983
 jquery¿¡¼­ Å×ÀÌºí¿¡ ¸¶¿ì½º ¿À¹ö½Ã ÇØ´ç ÇàÀÇ ¹è°æ»ö»ó º¯°æÇϱâ
2,982
 jquery ½ºÅ©¸³Æ®³» ƯÁ¤°ª È®ÀÎÇϱâ (µð¹ö±ë)
2,981
 jquery cookie (jquery.cookie.js)
2,980
 jquery div ±âº» ³ÐÀÌ, ³ôÀÌ °è»ê ¹× padding, border Æ÷ÇÔ Çϱâ
¸ñ·Ï
ÃßõÀ½¾Ç¹æ¼Û
ÀαâÀýÁ¤»Í¦ÆÄƼ
ÀÎ±âÆ®·ÎÆ®¸ðÀ½
Áö·ç¹Úµð½ºÄڸ޵鸮
¹ã¹«´ë¾Öâ°î
ÀüÀڿðհæÀ½¾Ç
¾ÞÄÝÆ®·ÎÆ®
»Í¦¾Æ°¡¾¾
TROT TV
¾Æ¸®¶û°¡¿ä
ÀÛÀº À½¾Ç´Ù¹æ
Á¾ÇÕ¼ºÀΰ¡¿ä¹æ
Ä«¹Ù·¹ À½¾Ç
Æ®·Ôµð½ºÄÚÆÎÆÎ
°ü±¤ ¸Þµé¸®
Æ®·ÔÄ«Æä
°¡¿ä°¨»ó½Ç
Ãß¾ïÀÇ¿¾³ë·¡
½ºÆä¼È°¡¿ä±¤Àå
BillBoard Free
Dance&Remix
Ãßõ°¡¿ä¸ðÀ½
°æÀ½¾Ç.ÀüÀڿðÕ
½ºÆä¼ÈÀ½¾Ç¿©Çà
WOLRD POPs
K-POP¡¬BillBoard
JP¡¬CN
POP TOP BEST
K.R.³ë·¡¹æ

Ãßõ°¡¿ä¡¬Àαâ
F¹ÂÁ÷ Àα⡬¹ß¶óµå
F¹ÂÁ÷ ¾Ö⡬Ʈ·ÎÆ®
Æ®·ÎÆ®¼ºÀΰ¡¿ä
ÀαⰡ¿ä
ÇÁ¸®¹Ì¾ö POP
°æÀ½¾Ç¡¬±âŸ
ÇÁ¸®¹Ì¾ö ÃֽŰ¡¿ä
ÇÁ¸®¹Ì¾ö ¼ºÀΰ¡¿ä
°¡¿ä1¹øÁö(Á¾ÇÕ)
¹ÂÁ÷ÇϿ콺
µ¿¿ä¡¬¿¬º¯¡¬¹ÝÁÖ¡¬±âŸ
°¡¿äÃàÁ¦¡¬Æ®·Ô1¹øÁö
´í½º¡¬¸Þµé¸®¡¬¸®¹Í½º
Ä«Æä¡¬¸í»ó¡¬°æÀ½¾Ç¡¬±âŸ
Ãßõ°¡¿ä¡¬POP¡¬±âŸ
ÃֽŰ¡¿ä¡¬ÀαⰡ¿ä
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½ÃºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æÄ§
Copyright (C) musictrot All rights reserved.