<?php 
# create PHP array: 
$php_array = array("one", "two", "three"); 
# "pass" php array to JS array: 
echo "<script language='JavaScript'>\n"; 
echo "var js_array = new Array();\n"; 
$ix = 0; 
foreach($php_array as $key => $value) 
{ 
  echo "js_array[$key] = $value;\n";
  echo "document.write("Hello Dolly");\n"; 
} 
# .....rest of JavaScript..... 
echo "</script>\n"; 

?>

this program gives a erroe like this

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\wamp\www\a.php on line 11

echo "document.write("Hello Dolly");\n";

Use single quotes

echo "document.write('Hello Dolly');\n";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.