【发布时间】:2016-04-12 18:06:02
【问题描述】:
我在一个 php 页面中设置了一个会话,该页面存储了一个数组,如下所示:
首页.php
$_SESSION["Counts"]=$some_array;
echo print_r($_SESSION["Counts"]);
输出:
Array ( [Finance] => Array ( [0] => 0 [1] => 3 [2] => 0 [3] => 0 [4] => 1 )
[Human resources] => Array ( [0] => 1 [1] => 5 [2] => 1 [3] => 0 [4] => 0 )
[Infrastructure] => Array ( [0] => 0 [1] => 3 [2] => 1 [3] => 0 [4] => 0 ) ) 1
在 .js 页面中检索会话数据 SecondJSpage.js
<script type="text/javascript">
var sessionValue= new Array();
var s= new Array();
var s1= new Array();
sessionValue = '<?php $_SESSION["Counts"]; ?>';
document.write(sessionValue); //Does not output anything
for( s1 in sessionValue) {
for( s in s1) {
document.write(s); //Does not output anything
document.write("<br />");
}}
</script>
只有数组没有被检索。一个简单的会话变量正在显示。如何解决这个问题?
【问题讨论】:
标签: javascript php arrays session