Basically, what I'm trying to do is send a request to a separate .php file which queries my database. The problem occurs when trying to return an array as a variable type array. I need this, because I want to send it to another PHP when it is send to the HTML. In the second PHP file, I want to use a for-each-loop-statement in order to create some code, but this only takes arrays and not strings. I've tried a couple of things including the use of JSON in an attempt to fix this, but on return the array keeps turning into a string. Any help would be appreciated. Most relevant code is included below:

javascript:

```
function getEvents(){ //gets the events from the database
  var req = new XMLHttpRequest();
  var att = 1;            //Just a filler because somehow this seems needed
  var link = "IekjeConnector.php";

  dataType:"json";
  req.onreadystatechange = function() {
    if(req.readyState === 4 && req.status === 200)
    {
      addEvents(JSON.parse(this.responseText)); //This should be a normal array
    }
  }
  req.open("GET", link + "?att=" + att, true);
  req.send();
}

function addEvents(events = ""){ 
  var req = new XMLHttpRequest();
  var link = "IekjeHome.php"; //sends to the next php

  req.onreadystatechange = function() {
    if(req.readyState === 4 && req.status === 200)
    { document.getElementById("event").innerHTML = this.responseText; }
  }

  req.open("GET", link + "?events=" + events, true); //events has the right value
  req.send();
}

```

php:

```
if (filter_input(INPUT_GET, "events", FILTER_SANITIZE_STRING)) {
  $events = filter_input(INPUT_GET, "events", FILTER_SANITIZE_STRING);
  $length = count($events);
  print_r(gettype($events));

  foreach($events as $event)
  { echo $events[$count] . $events[$count+2]; }
}

```

The foreach returns an error that $events is a string as does the gettype().
I tried changing the way addEvents and the php-code receive the array, but i'm probably doing something wrong trying.