Warning: Invalid argument supplied for foreach() in app/code/Magento/Config/Model/Config/Structure/Mapper/Sorting.php on line 34 (and my fix)

Magento 2 does not allow tabulation symbols inside config/system/section path in adminhtml/system.xml.
If you use tabs, you will got the message:

Warning: Invalid argument supplied for foreach() in app/code/Magento/Config/Model/Config/Structure/Mapper/Sorting.php on line 34

To fix it use spaces instead of tabs.

My analysis and fix

Step 1

The $data is \n\t\t here. It is not an array so we have an exception.

Step 2

The $element is \n\t\t here.
Look at the $data structure:

Step 3

The problem line is:

Step 4

The wrong line is:

How to fix it:

Replace the wrong line with the new one:

if ($children->length && trim($child->nodeValue, "\n\t ") === '') {