Warning: Undefined array key "mobile_dir" in /home/kagla/new-sir/old/common.php on line 315
script php 변수와 script 변수를 함께 사용 하는 방법

script php 변수와 script 변수를 함께 사용 하는 방법

script php 변수와 script 변수를 함께 사용 하는 방법

QA

script php 변수와 script 변수를 함께 사용 하는 방법

답변 3

본문

for(let i = 1;i <= 12;i++){
                let s = 'it_option_img';
                s+= i;
                let ss = "<?php echo $it["+s+"];?>";
            }

 

이렇게 사용하려고 하는데 안되는 이유를 모르겠습니다 ㅠㅠ

이 질문에 댓글 쓰기 :

답변 3

php 배열변수를 js 에서 굳이 사용하고싶으시면 이거 참고하세요

 


<?php
$tmp = array(
    array('a' => 1, 'b' => 11),
    array('a' => 2, 'b' => 22),
    array('a' => 3, 'b' => 33),
    array('a' => 4, 'b' => 44)
);
?>
<script type="text/javascript">
    var jsonString = '<?=json_encode($tmp)?>';
    var tmp = JSON.parse(jsonString);
    for (let i = 0;i < tmp.length;i++) {
        console.log(tmp[i]);
    }
</script>
답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 129,406
© SIRSOFT
현재 페이지 제일 처음으로