Accessing multidimensional array in JS created by PHP's json_encode

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 items 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!

Answers


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>

Need Your Help

How do I create a clickable item in menu to open a new activity?

android menu android-activity clickable

I have made an app with a lot of buttons and activities. I'm having trouble though understanding how to start a new activity through a button that is in my menu (when the menu button is clicked on ...

Getting error on gettext from edittext?

android string gettext

I'm making a simple application that changes images when a certain string is typed in a dialog box but when I try to get the string from edit text(in the dialog) the application stops and gives an ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.