답변 3개
가령 1,2,3,4 를 뿌려주는 함수가 $i 라고 하면
</strong> </p><pre><p style="margin-left: 40px;">for($i = 1 ; $i <= 5 ;$i++){//
if($i == 2){ // 2를 출력하려고할때 </p><p style="margin-left: 40px;"> echo 76 ; // 76 출력</p><p style="margin-left: 40px;"> }else{ </p><p style="margin-left: 40px;"> echo $i; // 아니면 해당 숫자를 출력</p><p style="margin-left: 40px;"> } // end if</p><p style="margin-left: 40px;">}//end for</p><p style="margin-left: 0px;"><strong style="color: rgb(127, 127, 127); font-family: Arial, 돋움, Dotum; font-size: 12px; white-space: normal;">
결과
1 ,76,3,4,5
</strong>
</p><p style="margin-left: 40px;">/**********************************/</p><p style="margin-left: 40px;">
</p><pre style="font-size: 14.6667px;"><p style="margin-left: 40px;">for($i = 1 ; $i <= 5 ;$i++){//
if($i == 2){ // 2를 출력하려고할때 </p><p style="margin-left: 40px;"> <span style="font-size: 14.6667px; font-family: 돋움;">continue; // 그냥 loop를 건너 뜁니다.</span></p><p style="margin-left: 40px;"> }else{ </p><p style="margin-left: 40px;"> echo $i; // 아니면 해당 숫자를 출력</p><p style="margin-left: 40px;"> } // end if</p><p style="margin-left: 40px;">}//end for</p><p style="margin-left: 40px;"><strong style="color: rgb(127, 127, 127); font-family: Arial, 돋움, Dotum; font-size: 12px; white-space: normal;">
출력 결과
1,3,4,5
댓글을 작성하려면 로그인이 필요합니다.
</strong></p><p>
</p><p><span style="font-family: Arial, 돋움, Dotum; color: rgb(127, 127, 127);"><span style="font-size: 12px;"><b>for($i = 1 ; $i <= count($rst) ;$i++){//</b></span></span><b style="color: rgb(127, 127, 127); font-family: Arial, 돋움, Dotum; font-size: 12px;">$rst 는 리스트 문자열</b></p><p style="margin-left: 40px;"><span style="font-family: Arial, 돋움, Dotum; color: rgb(127, 127, 127);"><span style="font-size: 12px;"><b>echo $i; /// not $rst['wr_id']</b></span></span></p><p><span style="font-family: Arial, 돋움, Dotum; color: rgb(127, 127, 127);"><span style="font-size: 12px;"><b>}</b></span></span></p><p><strong style="color: rgb(127, 127, 127); font-family: Arial, 돋움, Dotum; font-size: 12px;">
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
for($i=0;$i<5;$i++){
if ($i==2) {
continue;
}
echo "i = ".$i." ";
}
이렇게 돌고있다는 건가요?
만약 맞다면 빨간 글씨 if (조건) { continue; } 를 주석처리 하시면 될 겁니다
답변에 대한 댓글 2개
2가아닌 뜬금없는 숫자 76을 넣는다면 어떻게해야할까요..
if ($i==2) { echo "i = "."76"."<br>";
} else {
echo "i = ".$i."<br>";
}
}
이렇게 하시면 됩니다
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
2가아닌 뜬금없는 숫자 76을 넣는다면 어떻게해야할까요..