Access a PHP array element by using a JavaScript variable as index -


the code looks this:

php file

<?php ... $arrayname = ['arrayvalue_0', ..., 'arrayvalue_n']; ... php?> 

javascript

$('.elementclass').each(function(index, id) {     $(id).html('<?php echo $arrayname[index - 1]?>'); }); 

but can't insert javascript variable php tags index never received. know can done via ajax there other way? in advance.

additional info: i've been told in php there's no posibility of switching array js file.

you can define arrayname variable in js , initialize value server:

var arrayname = <?php echo json_encode($arrayname); ?>; $(".elementclass").each(function(index, id) {     $(id).html(arrayname[index-1]); }); 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -