Already wanted to ask the PHP cracks here, but finally found the solution myself and would like to share it.
I was trying to sort a related set (multiple-field sort) using PHP itself, not by setting up portal sorting in the database, in order to avoid strain on the database server.
After digging through x forum pages proposing techniques such as
array_sort_by_column(), array_multisort (which all did not work, usually because they could not handle the complex FileMaker_Result object ) I have found a very simple solution.
In the FileMaker database:
Delete your original portal on the layout and create it again (copy-paste won't work), and add the fields in the sequence they should be sorted.
In your PHP code:
$relatedset = $record->getRelatedSet('your_layout_name');
// foreach ($relatedset as ...
This works if all fields can be sorted in one direction (which did not matter to me in my specific case).
I would be interested to hear what PHP techniques you are using.
In XML/XSLT publishing, one could indicate individual fields for sorting. Example:
<xsl:for-each select="$topic/fmrs:relatedset[@table = 'related_table']/fmrs:record">
<xsl:sort data-type="text" order="ascending" select="fmrs:field[@name = 'related_table_xy::field1']/fmrs:data"/>
<xsl:sort data-type="text" order="ascending" select="fmrs:field[@name = 'related_table_xy_or_z::field2']/fmrs:data"/>