-3

I'm struggle to find an answer for this so was hoping to hear from the community.

$('.slick-dots button').each(function(index) {
    $(this).html('<?php echo $headings[0]; ?>')
});

Within the above .each function, I am trying to increase $headings[0] by one on each loop.

Hopefully I'm missing something pretty simple and I've not gone down an impossible route?

Nick
  • 876
  • 1
  • 14
  • 35
  • 6
    Have a look [here](http://programmers.stackexchange.com/questions/171203/what-are-the-differences-between-server-side-and-client-side-programming) – empiric Jun 23 '16 at 18:57
  • 1
    You're going to get the usual "Don't mix Javascript and PHP" comments here. Incrementing a PHP (server-side) array in a Javascript (client-side) loop isn't something you can do. – Tim Lewis Jun 23 '16 at 18:58
  • Thanks @TimLewis looks like I'm going about this the complete wrong way. Any thoughts on a good route to take starting fresh with the goal of achieving the same thing? – Nick Jun 23 '16 at 19:04
  • Not sure if I agree with choice of "duplicate". It tells why it can be done, but doesn't offer a real solution. This is probably more helpful to the OP and future readers: http://stackoverflow.com/questions/23740548/how-to-pass-variables-and-data-from-php-to-javascript – Pevara Jun 23 '16 at 19:13
  • Jay Blanchard has marked this as an 'exact duplicate of an existing question'. Perhaps we have different ideas of what 'exact duplicate' means? – Nick Jun 23 '16 at 19:13
  • @Nick maybe you could request your php array via ajax and process the response accordingly – empiric Jun 23 '16 at 19:14
  • Unfortunately I'm really not familiar with AJAX. I have however resolved the problem by running: inside the php loop to a JS variable outside of it. Perhaps that will get me torn apart at StackOverflow, I just needed something that functioned. – Nick Jun 23 '16 at 19:15

1 Answers1

1

Because the PHP runs before the page loads $headings won't receive the data you are trying to pass to it

WorkHardWork
  • 92
  • 10