I have been searching the web like crazy for a day straight trying to figure out why my javascript code is not working. I am trying to pass an array from PHP to Javascript using JSON. After that i want to use it in other functions, thus kinda making the array or variable global. But i have been unable to get it to work, here is my code so far:
data = [];
$(document).ready(function() {
  $.getJSON('database.php', function(phpdata){
    // vad du vill göra här, allt retuneras i data-variabeln
    console.log(phpdata);
    data[0] = phpdata[0];
    console.log(data[0]);
  });
console.log(data);
Any ideas?
 
     
    