How to convert php array variable to javascript variable -


this question has answer here:

here code retrieving db... , stored column values in array() variable...

$res1 = array(); while ($row = mysql_fetch_assoc($res)) {     $res1[$i] = $row['address'];     $i = $i + 1; }  print_r($res1); 

but problem wen trying print array printing below:

"array ( [0] => ameerpet [1] => panjagutta )" 

but need print array below can store in js variable further using......

["ameerpet", "panjagutta"]; 

use json_encode() encode array json format:

$json = json_encode($res1); 

you can use variable in javascript , use use json.parse():

json = <?php echo $json; ?> var obj = json.parse(json); // obj contains array 

documentation: json.parse()


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -