title: Parse returned 2D-Array from PHP-Script to Javascript-Variable inside a Wordpress-Codeblock
body: <p>So I have a standard php-script, which is stored in an external php-file that is located on the server in the main folder (in this case /html/mysite/getlocations.php).</p>
  
  <pre><code>&lt;?php
  
  function getData() {
  // MySQL-Connection-Variables
  $servername = "xxxxxxxxxx.hosting-data.io";
  $username = "xxxxxxxxxxxxxxxxxx";
  $password = "xxxxxxxxxxxxxx";
  $dbname = "xxxxxxxxxxxx";
  
  // Create connection
  $conn = mysqli_connect( $servername, $username, $password, $dbname );
  $conn_number = mysqli_connect( $servername, $username, $password, $dbname );
  // Check connection
  if ( !$conn ) {
      die( "Connection failed: " . mysqli_connect_error() );
  }
  
  // SQL-Query for Locations
  $sql = "SELECT ID, Beschreibung, Straße, Hausnummer, PLZ, Ort, Bezirk, Leiter, Email, Telefon, Website FROM Locations";
  //SQL-Query for Number of Entries
  $sql_number = "SELECT COUNT(*) FROM Locations;"
  $result = mysqli_query( $conn, $sql );
  // Size of MySQL-Table
  $size = mysqli_query( $conn_number, $sql );
  $counter = 0;
  
  // 2D-Array with all the needed informations for further processing
  $returnarray = array();
  
  // Number of Table-Entries &gt; 0
  if ( mysqli_num_rows( $result ) &gt; 0 ) {
      // Iterate over all Entries
      while ( $row = mysqli_fetch_assoc( $result ) ) {
  
      $desription = $row[ "Beschreibung" ];
      $street = $row[ "Straße" ];
      $number = $row[ "Hausnummer" ];
      $plz = $row[ "PLZ" ];
      $city = $row[ "Ort" ];
      $bezirk = $row[ "Bezirk" ];
      $leiter = $row[ "Leiter" ];
      $email = $row[ "Email" ];
      $phone = $row[ "Telefon" ];
      $website = $row[ "Website" ];
  
      $returnarray[$counter] = array();
      $returnarray[$counter]['name'] = $desription;
      $returnarray[$counter]['street'] = $street;
      $returnarray[$counter]['number'] = $number;
      $returnarray[$counter]['plz'] = $plz;
      $returnarray[$counter]['city'] = $city;
      $returnarray[$counter]['bezirk'] = $bezirk;
      $returnarray[$counter]['leiter'] = $leiter;
      $returnarray[$counter]['email'] = $email;
      $returnarray[$counter]['telefon'] = $telefon;
      $returnarray[$counter]['website'] = $website;
      $counter = $counter + 1;
    }
  }
  
  
  // Close connection
  mysqli_close( $conn );
  
  return $returnarray;
  }
  
  echo getData();
  
  ?&gt;
  </code></pre>
  
  <p>This php-scripts connects to a mysql-database, fetches information and stores it in a twodimensional array.</p>
  
  <p>Now I want to retrieve this returned array and put it in a javascript-variable, so I can use it for further processing inside a Wordpress-Codeblock.</p>
  
  <p>So my attempt was this:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  var data_from_ajax;
  
  $.get('/html/mysite/getlocations.php', function(data) {
    data_from_ajax = data;
  });
  
  &lt;/script&gt;
  </code></pre>
  
  <p>But this didnt work like I intended it would.</p>