Array from Structure is in wrong order

Hi,
I am trying to create a CSV file from a structure. Everything is going fairly well, I have a hook writing the CSV on page update, and it is getting the data from the structure. This is my code:

'page.update:after' => function (Kirby\Cms\Page $newPage, Kirby\Cms\Page $oldPage) {
  $data = $newPage->spreadsheet()->toStructure()->toArray();
  $newFile = $newPage->root() . '/' . $newPage->slug() . '.csv';
  $fp = fopen($newFile, 'w');
  foreach($data as $items) {
    fputcsv($fp, $items);
  }
  fclose($fp);
},

However, the array that is written has the structure fields in the wrong order. These are the stucture fields:


columnOne:
  label: 1
  type: writer
  nodes: false
  inline: true
  marks:
    - italic
    - link
columnTwo:
  label: 2
  type: writer
  nodes: false
  inline: true
  marks:
    - italic
    - link
columnThree:
  label: 3
  type: writer
  nodes: false
  inline: true
  marks:
    - italic
    - link
columnFour:
  label: 4
  type: writer
  nodes: false
  inline: true
  marks:
    - italic
    - link
columnFive:
  label: 5
  type: writer
  nodes: false
  inline: true
  marks:
    - italic
    - link

But the array, and the csv produced from it, have the fields alphabetised based on the fieldname, like so:

columnfive,columnfour,columnone,columnthree,columntwo,0

These is also the index number at the end, but that is another story! Is there a better way to go about what I am doing, or to fix the issue I am seeing with my method?

I you instead of toStructure()->toArray() use

  $data = $newPage->spreadsheet()->yaml();

you solve both problems.

That is perfect, working exactly as I need it to. Thank you!