duanlin1931 2012-06-19 23:24
浏览 38
已采纳

如何从PHP数组中检索值?

I have a array stored in a PHP file in which I am storing all the values.

I am trying to loop through the entire array in JavaScript. How should I do that?

The following does not work:

var index = 0;
var info = 1;

while(index<4) {
    info = <?php echo $a[?>index<?php];?>
    index++;
}
  • 写回答

4条回答 默认 最新

  • douza19870617 2012-06-19 23:29
    关注

    I don't know what version of php you're using, but try something like this:

    var info = null;
    var a = <?php echo json_encode($a); ?>;
    
    for(var index=0;index<a.length;index++) {
        info = a[index];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?