如何从MYSQL查询顺序推入数组?

The php and js are the following:

    createRoomTable()

    function createRoomTable(){
      $.post('../include/returnRoomTable.php',{
        //nothing to transmit
      }).then((returnedTableMarkup) => {
        returnedTableMarkup = JSON.parse(returnedTableMarkup)
        console.log("data from returnRoomTable.php is ", returnedTableMarkup)
        //$('#roomTableOutput').html(returnedTableMarkup)
      })
    }
<?php
session_start();

try{
  $connection = new PDO('mysql:host=localhost;dbname=XXXX',
  'XXXX','XXXXXX');
}catch(PDOException $e){
  echo $e->getMessage();
}

$allRooms = $connection->query("
SELECT name
FROM raum
")->fetchAll(PDO::FETCH_NUM);

$indexLimit = count($allRooms);
$allSeats = [];
for($index = 0; $index < $indexLimit; $index++){
  $allSeats =  array_push($connection->query("
  SELECT nummer
  FROM arbeitsplatz
  WHERE raum = '".$allRooms[$index]."'
  ")->fetchAll(PDO::FETCH_NUM));
}

echo json_encode ($allSeats);

?>

So currently, consolelog says the array is "null". What I need is a flexible, two-dimensional array ("$allSeats") which takes each iteration from the MYSQL query and puts it into this array. The problem is that I'm not very experiences with arrays in php, and I'm out of ideas how I can accomplish this.

</div>

Okay, so I found a solution to my problem myself:

The php now looks like this:

<?php
session_start();

try{
  $connection = new PDO('mysql:host=localhost;dbname=arbeitsplatzverwaltung',
  'verwalter','N7pY1OTl2gaBbc51');
}catch(PDOException $e){
  echo $e->getMessage();
}

$allRooms = $connection->query("
SELECT name
FROM raum
")->fetchAll(PDO::FETCH_NUM);

$indexLimit = count($allRooms);
$allSeats = [];

for($index = 0; $index < $indexLimit; $index++){
  $currentQuery = $connection->query("
  SELECT nummer
  FROM arbeitsplatz
  WHERE raum = '".$allRooms[$index][0]."'
  ")->fetchAll(PDO::FETCH_NUM);

  array_push($allSeats, $currentQuery);
}
/*
$allSeats[] = $connection->query("
 SELECT nummer
 FROM arbeitsplatz WHERE raum = '".$allRooms[$index]."'
 ")->fetchAll(PDO::FETCH_NUM);*/

echo json_encode ($allSeats);

?>

And when I output this in my JS, I get an array of arrays containing the values.

</div>