4

I've tried

var name = <?php echo json_encode($eventname); ?>; 

and

var name = new Array("<?php echo implode('","', $eventName);?>"); 

to parse my name string array from PHP to Javascript. It displayed as

var name = ["lalalala","Lalala","test"]; 

and

var name = new Array("lalalala","Lalala","test"); 

in viewsource, but when I tried to use name[i] to get the string, it returned the character, not the string. The size of the array name is also not 3, but 20 (which is the total number of characters plus three ","). How can I fix this?

Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
abenoy05
  • 43
  • 3

1 Answers1

5

Pretty sure because 'name' points to window.name (Thanks Fabrício Matté). Look Here

It works fine if you change 'name' to 'names'.

Community
  • 1
  • 1
Dave Chen
  • 10,887
  • 8
  • 39
  • 67