开发者

Accessing multidimensional array in JS created by PHP's json_encode

开发者 https://www.devze.com 2023-01-28 11:06 出处:网络
Here is some PHP code: $map[1][3][\'test\'][0]=\'weee\'; $map[4][5][\'test\'][0]=\'bleh\'; $map[1][3][\'bleh\'][0]=\'mooo\';

Here is some PHP code:

$map[1][3]['test'][0]='weee';
$map[4][5]['test'][0]='bleh';
$map[1][3]['bleh'][0]='mooo';
$map[1][3]['bleh'][1]='baaa';
echo "map = " . json_encode($map) . ";";

How do I access these i开发者_如何学Ctems in Javascipt?

I've tried all sorts:

map[1][3]['bleh'][1]
map[1][3].bleh[1]
map.1.3.bleh[1]

but nothing seems to work :(

Thanks!


Works for me, except for your last one

<html>
<body>
<script type="text/javascript">
<?php

$map[1][3]['test'][0]='weee';
$map[4][5]['test'][0]='bleh';
$map[1][3]['bleh'][0]='mooo';
$map[1][3]['bleh'][1]='baaa';

print "map = ".json_encode($map).";\n";
?>

alert(map[1][3]['bleh'][1]);
alert(map[1][3].bleh[1]);

</script>
</body>
</html>
0

精彩评论

暂无评论...
验证码 换一张
取 消