Using javascript for loop, access php array variables -


a small problem can't seem figure out;

so have php array in want access through javascript using loop specify index. example,

<?php   $myarray = array("a", "b", "c"); ?>  <script type="text/javascript"> for(var = 0; < elements.length; i++){         $('<div class="pops"> hello '+ want php variables +'</div>').appendto(elements[i]); </script> 

i access variables in $myarray using 'i' in javascript loop since there same number of variables loop iterations.

i have tried read on possible solutions solve have not been able figure out. have tried using following code came nothing;

$('<div class="pops"> hello '+ <?php echo $myarray[i]; ?> +'</div>').appendto(elements[i]); 

i feel running trouble here because of following 2 reasons; syntax wrong. 'i' variable using access index of array still javascript variable.

i new javascript/php please forgive me. sort of help!

easy, convert json , add script element.

<?php $myarray = array("a", "b", "c"); ?>  <script type="text/javascript">  // assume phparray length equals elements length  var phparray = <?php echo json_encode($myarray); ?> ; for(var = 0; < elements.length; i++){     $('<div class="pops"> hello '+ phparray[i] +'</div>').appendto(elements[i]);  </script> 

Comments

Popular posts from this blog

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -