테스트 사이트 - 개발 중인 베타 버전입니다

for 문이 어떻게 되나요~~ 채택완료

카산 1년 전 조회 3,724

다음과 같은 것을 for 문으로 표현하려는데 도통 에러만 나고 되질 않네요~~ 어디가 잘못인가요?

</p>

<p>$latest_out_01 = $cf_bs02['1'];

$latest_skin_01 = $cf_bs02['2'];

$latest_board_id_01 = $cf_bs02['3'];

$latest_group_id_01 = $cf_bs02['4'];

$latest_line_number_01 = $cf_bs02['5'];

$latest_text_lenght_01 = $cf_bs02['6'];</p>

<p>$latest_out_02 = $cf_bs02['7'];

$latest_skin_02 = $cf_bs02['8'];

$latest_board_id_02 = $cf_bs02['9'];

$latest_group_id_02 = $cf_bs02['10'];

$latest_line_number_02 = $cf_bs02['11'];

$latest_text_lenght_02 = $cf_bs02['12'];</p>

<p>$latest_out_03 = $cf_bs02['13'];

$latest_skin_03 = $cf_bs02['14'];

$latest_board_id_03 = $cf_bs02['15'];

$latest_group_id_03 = $cf_bs02['16'];

$latest_line_number_03 = $cf_bs02['17'];

$latest_text_lenght_03 = $cf_bs02['18'];</p>

<p>$latest_out_04 = $cf_bs02['19'];

$latest_skin_04 = $cf_bs02['20'];

$latest_board_id_04 = $cf_bs02['21'];

$latest_group_id_04 = $cf_bs02['22'];

$latest_line_number_04 = $cf_bs02['23'];

$latest_text_lenght_04 = $cf_bs02['24'];</p>

<p>$latest_out_05 = $cf_bs02['25'];

$latest_skin_05 = $cf_bs02['26'];

$latest_board_id_05 = $cf_bs02['27'];

$latest_group_id_05 = $cf_bs02['28'];

$latest_line_number_05 = $cf_bs02['29'];

$latest_text_lenght_05 = $cf_bs02['30'];</p>

<p>$latest_out_06 = $cf_bs02['31'];

$latest_skin_06 = $cf_bs02['32'];

$latest_board_id_06 = $cf_bs02['33'];

$latest_group_id_06 = $cf_bs02['34'];

$latest_line_number_06 = $cf_bs02['35'];

$latest_text_lenght_06 = $cf_bs02['36'];</p>

<p>$latest_out_07 = $cf_bs02['37'];

$latest_skin_07 = $cf_bs02['38'];

$latest_board_id_07 = $cf_bs02['39'];

$latest_group_id_07 = $cf_bs02['40'];

$latest_line_number_07 = $cf_bs02['41'];

$latest_text_lenght_07 = $cf_bs02['42'];</p>

<p> </p>

<p>위의 내용을 아래와 같이 했습니다</p>

<p>for($j=1;$j<=42;$j+=6)

${"latest_out_0".sprintf('%d', $j+5/6)} = $cf_bs02[$j];

${"latest_skin_0".sprintf('%d', $j+5/6)} = $cf_bs02[$j+1];

${"latest_board_id_0".sprintf('%d', $j+5/6)} = $cf_bs02[$j+2];

${"latest_group_id_0".sprintf('%d', $j+5/6)} = $cf_bs02[$j+3];

${"latest_line_number_0".sprintf('%d', $j+5/6)} = $cf_bs02[$j+4];

${"latest_text_lenght_0".sprintf('%d', $j+5/6)} = $cf_bs02[$j+5];</p>

<p>

댓글을 작성하려면 로그인이 필요합니다.

답변 4개

채택된 답변
+20 포인트
들레아빠

</p>

<p>for ($i = 1; $i <= 7; $i++) {

    $latest_out[$i] = $cf_bs02[($i - 1) * 6 + 1];

    $latest_skin[$i] = $cf_bs02[($i - 1) * 6 + 2];

    $latest_board_id[$i] = $cf_bs02[($i - 1) * 6 + 3];

    $latest_group_id[$i] = $cf_bs02[($i - 1) * 6 + 4];

    $latest_line_number[$i] = $cf_bs02[($i - 1) * 6 + 5];

    $latest_text_length[$i] = $cf_bs02[($i - 1) * 6 + 6];

}

로그인 후 평가할 수 있습니다

답변에 대한 댓글 2개

카산
1년 전
답변감사합니다~~ 덕분에 잘 해결하였습니다~~

그런데 혹시 위에 제가 한것은 무엇이 잘못되었는지 가르침 주실수 있는지요~~
제가 이리저리 홈피만들면서 재미삼아 공부중이거든요~~ 서비스는 컨텐츠가 없어서 불가하구요~~
들레아빠
1년 전
채택 감사 합니다.

sprintf('%d', $j+5/6) 표현식이 올바르지 않습니다.
$j 값에 5/6을 더한 후 정수로 변환하려고 하지만, 이 표현식은 의도한 대로 작동하지 않습니다.
대신, 올바른 인덱스를 계산하기 위해 (int)(($j + 5) / 6)를 사용할 수 있습니다.

댓글을 작성하려면 로그인이 필요합니다.

카산
1년 전

들레아빠님 감사합니다

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

카산
1년 전

감사합니다~~ 위로까지 ~퇴직 백수의 길이 아주 즐겁습니다

처음에 알려주신 것은 이상없이 잘 되는데 아래 제게 올린것 수정해주신 것은 되기는 되는데 아래와 같은 오류가 한줄 뜨네요~~

Warning: Undefined array key 42 in D:\Apache24\htdocs\theme\dw_bootstrap\include\out_option.php on line 138

 

위의 138라인이 

${"latest_text_length_0".(int)(($j + 5) / 6)} = $cf_bs02[$j + 5]; 

거든요
로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

들레아빠
1년 전
latest_text_length_0
=>
latest_text_lenght_0

댓글을 작성하려면 로그인이 필요합니다.

카산
1년 전

들레아빠님 추가 답변 고맙습니다~~ 혼자 공부하자니 맨날 초보 탈출이 안됩니다

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

들레아빠
1년 전
초보라고 하시면 이미 초보를 벗어 나셨습니다. 공부는 영원히 다할 수 없습니다.
[code]
for($j = 1; $j <= 42; $j += 6) {
${"latest_out_0".(int)(($j + 5) / 6)} = $cf_bs02[$j];
${"latest_skin_0".(int)(($j + 5) / 6)} = $cf_bs02[$j + 1];
${"latest_board_id_0".(int)(($j + 5) / 6)} = $cf_bs02[$j + 2];
${"latest_group_id_0".(int)(($j + 5) / 6)} = $cf_bs02[$j + 3];
${"latest_line_number_0".(int)(($j + 5) / 6)} = $cf_bs02[$j + 4];
${"latest_text_length_0".(int)(($j + 5) / 6)} = $cf_bs02[$j + 5];
}
[/code]

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인