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
Post a Comment