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

변수 반복문을 통해서 출력 채택완료

승슝 3년 전 조회 1,892

안녕하세요, 여분필드의 변수에 값을 넣으려고 하는데 반복문을 통해 변수를 설정할 수 없을까 궁금하여 질문드립니다.

 

</p>

<p>$wr_1 = "$facility[0]";</p>

<p>$wr_2 = "$facility[1]";</p>

<p>$wr_3 = "$facility[2]";</p>

<p>$wr_4 = "$facility[3]";</p>

<p>$wr_5 = "$facility[4]";</p>

<p>$wr_6 = "$facility[5]";</p>

<p>$wr_7 = "$facility[6]";</p>

<p>$wr_8 = "$facility[7]";</p>

<p>$wr_9 = "$facility[8]";</p>

<p>$wr_10 = "$facility[9]";</p>

<p>$wr_11 = "$facility[10]";</p>

<p>$wr_12 = "$facility[11]";</p>

<p>$wr_13 = "$facility[12]";</p>

<p>$wr_14 = "$facility[13]";</p>

<p>$wr_15 = "$facility[14]";</p>

<p>$wr_16 = "$facility[15]";</p>

<p>$wr_17 = "$facility[16]";</p>

<p>$wr_18 = "$facility[17]";</p>

<p>$wr_19 = "$facility[18]";</p>

<p>$wr_20 = "$facility[19]";</p>

<p>$wr_21 = "$facility[20]";</p>

<p>$wr_22 = "$facility[21]";</p>

<p>$wr_23 = "$facility[22]";</p>

<p>$wr_24 = "$facility[23]";</p>

<p>$wr_25 = "$facility[24]";</p>

<p>$wr_26 = "$facility[25]";</p>

<p>$wr_27 = "$facility[26]";</p>

<p>$wr_28 = "$facility[27]";</p>

<p>$wr_29 = "$facility[28]";</p>

<p>$wr_30 = "$facility[29]";</p>

<p>$wr_31 = "$facility[30]";</p>

<p>$wr_32 = "$facility[31]";</p>

<p>$wr_33 = "$facility[32]";</p>

<p>$wr_34 = "$facility[33]";</p>

<p>$wr_35 = "$facility[34]";</p>

<p>$wr_36 = "$facility[35]";</p>

<p>$wr_37 = "$facility[36]";</p>

<p>$wr_38 = "$facility[37]";</p>

<p>$wr_39 = "$facility[38]";</p>

<p>$wr_40 = "$facility[39]";</p>

<p>$wr_41 = "$facility[40]";</p>

<p>$wr_42 = "$facility[41]";</p>

<p>$wr_43 = "$facility[42]";</p>

<p>$wr_44 = "$facility[43]";</p>

<p>$wr_45 = "$facility[44]";</p>

<p>$wr_46 = "$facility[45]";</p>

<p>$wr_47 = "$facility[46]";</p>

<p>$wr_48 = "$facility[47]";</p>

<p>$wr_49 = "$facility[48]";</p>

<p>$wr_50 = "$facility[49]";</p>

<p>

 

이런식으로 값을 저장하는데 반복은 사용은 어렵고 이렇게 직접 작성하는 것밖에 없을까요?

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

답변 4개

채택된 답변
+20 포인트

답변에 대한 댓글 1개

승슝
3년 전
[code]
for($z = 1; $z < 4 ; $z ++){
$num.$z = "numver".$z;
}
[/code]
이런식으로 num의 이름 뒤에 숫자도 증가했으면 좋겠는데요...!! 방법이 없을까요

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

n
3년 전

추가 피해자 방지 https://sir.kr/conflictconsultation/245" rel="nofollow noreferrer noopener" target="_blank">https://sir.kr/conflictconsultation/245

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

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

s
sinbi Expert
3년 전

잘 되는지 확인해 보세요.

</p>

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

    ${"wr_".$i} = (string) $facility[${$i-1}];

}</p>

<p>

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

답변에 대한 댓글 1개

승슝
3년 전
진짜 감사합니다!! 해결되었습습니다~!!!

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

유찬아빠

for($i=1,$k=0;$i<51;$i++,$k++){

$wr_.$i = $facility[$k];
}

이렇게 하면 되지 않을까요?

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

답변에 대한 댓글 1개

승슝
3년 전
저도 이렇게 하면 될 줄 알았는데 안되더라구요ㅜㅜ

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

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

로그인