Friday, January 20, 2012

Passing PHP array to JavaScript array


Below is the example passing PHP array qid[] and qtype[] array to Javascript array
question_num0[] and question_type[].

<script type="text/javascript">
<!--//--><![CDATA[//><!--

var question_type = new Array();
var  question_num0= new Array();

<?php
$count =10;
 for($j=0; $j<$count; $j++){
 echo "question_num0[$j]=$qid[$j];\n";
 echo "question_type[$j]=\"$qtype[$j]\";\n";
 }
?>

//Write your JavaScript here using array  question_num0 and question_type
//--><!]]>
</script>

1 comment:

  1. Most of the times you need to utilize the parsing function in PHP and it is good to see a useful tutorial how to embed java function in php to parse. If you are willing for more java help you can also visit programming forums.

    ReplyDelete