faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

79 of 136 people (58%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

How to insert in a javascript array the elements of a php array ?

Nov 27th, 2008 02:40
healthy man, dman, Wynand Wolmarans, youf yipiha, http://www.ttnr.org


Here is a simple example of code that will put your php array into 
javascript. You should probably call this function in your head-part of 
your html page:
function j_array($var){
	$javastr = "<script language=\"javascript\">";
	$javastr .= "var d = new Array();";
	while(list($key, $val) = each($var)){
	      $javastr .= "d[$key] = '$val';";
	}
	$javastr .= "</script>";
return $javastr;
}
print "<html>";
print "</head>";
echo j_array($php_array);
print "</head>";
http://www.healthdothealth.com
http://www.healthxhealth.com
http://www.mesotheliomainmesothelioma.com
http://www.healthfirewall.com
http://www.flathealth.com
http://www.healthbodyguard.com