변수 반복문을 통해서 출력

변수 반복문을 통해서 출력

QA

변수 반복문을 통해서 출력

답변 4

본문

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

 


$wr_1 = "$facility[0]";
$wr_2 = "$facility[1]";
$wr_3 = "$facility[2]";
$wr_4 = "$facility[3]";
$wr_5 = "$facility[4]";
$wr_6 = "$facility[5]";
$wr_7 = "$facility[6]";
$wr_8 = "$facility[7]";
$wr_9 = "$facility[8]";
$wr_10 = "$facility[9]";
$wr_11 = "$facility[10]";
$wr_12 = "$facility[11]";
$wr_13 = "$facility[12]";
$wr_14 = "$facility[13]";
$wr_15 = "$facility[14]";
$wr_16 = "$facility[15]";
$wr_17 = "$facility[16]";
$wr_18 = "$facility[17]";
$wr_19 = "$facility[18]";
$wr_20 = "$facility[19]";
$wr_21 = "$facility[20]";
$wr_22 = "$facility[21]";
$wr_23 = "$facility[22]";
$wr_24 = "$facility[23]";
$wr_25 = "$facility[24]";
$wr_26 = "$facility[25]";
$wr_27 = "$facility[26]";
$wr_28 = "$facility[27]";
$wr_29 = "$facility[28]";
$wr_30 = "$facility[29]";
$wr_31 = "$facility[30]";
$wr_32 = "$facility[31]";
$wr_33 = "$facility[32]";
$wr_34 = "$facility[33]";
$wr_35 = "$facility[34]";
$wr_36 = "$facility[35]";
$wr_37 = "$facility[36]";
$wr_38 = "$facility[37]";
$wr_39 = "$facility[38]";
$wr_40 = "$facility[39]";
$wr_41 = "$facility[40]";
$wr_42 = "$facility[41]";
$wr_43 = "$facility[42]";
$wr_44 = "$facility[43]";
$wr_45 = "$facility[44]";
$wr_46 = "$facility[45]";
$wr_47 = "$facility[46]";
$wr_48 = "$facility[47]";
$wr_49 = "$facility[48]";
$wr_50 = "$facility[49]";

 

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

이 질문에 댓글 쓰기 :

답변 4

잘 되는지 확인해 보세요.


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

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

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

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

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 171
© SIRSOFT
현재 페이지 제일 처음으로