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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -