在PHP中获取多个foreach语句之外的数据

I'm trying to fetch data from multiple tables but I'm having a couple of issues with data I try to obtain inside the first foreach statement.

(I'm using medoo.in by the way).

$sales_order = $database->select("sales_order", "*", ["status" => "processing"]);
foreach($sales_order as $salesOrder) {
  $entity_id = $salesOrder['entity_id'];

  // Some other data from the sales_order table

  $sales_order_item = $database->select("sales_order_item", "*", ["order_id" => $entity_id]);

  foreach($sales_order_item as $salesOrderItem) {
    // Other data from the sales_order_item table
    $productID[] = $salesOrderItem['product_id'];
    $sku[] = $salesOrderItem['sku'];
    $qty[] = $salesOrderItem['qty_ordered'];

}

// Then dump the SKU to test data output
var_dump($sku);

}

As you can see above $sales_order_item needs to be inside the first foreach because I need the $entity_id, but doing this causes me problems. It seems to repeat the output of my data:

  array(4) {
  [0]=>
  string(20) "FT0058P-White-Medium"
  [1]=>
  string(20) "FT0058P-White-Medium"
  [2]=>
  string(26) "FT0058P-Heather Grey-Large"
  [3]=>
  string(26) "FT0058P-Heather Grey-Large"

}

Is there a better method of doing what I'm trying to achieve?