var stds = [];
<?php
foreach ($this->students as $key => $value){
?>
var smval = "<?php echo $value?>";
stds.push( smval );
<?php
}
?>
alert("stds"+stds);
alert(“stds”+stds);//print abc,bcd,efg so on…
The above code works fine for pushing Student Names.
Now I want to push student CODES also which is there in value $key.
How can i create an associative array to do that
The cleanest and safest way to do this is to convert the PHP object into a JavaScript object literal with json_encode: