子 MajorDescription の値に基づいて、次の XML (foreach ProgramList) を並べ替える必要があります。
<ArrayOfProgramList xmlns="http://schemas.datacontract.org/2004/07/Taca.Resources" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ProgramList>
<AreaOfInterests xmlns:a="http://schemas.datacontract.org/2004/07/Taca">
<a:AreaOfInterest>
<a:Interest>ABORIGINAL STUDIES</a:Interest>
</a:AreaOfInterest>
</AreaOfInterests>
<Coop>true</Coop>
<MajorDescription>ABORIGINAL COMMUNITY AND SOCIAL DEVELOPMENT</MajorDescription>
<Program>ACSD</Program>
<ProgramLocations>
<ProgramLocation>
<Campus>Barrie</Campus>
</ProgramLocation>
</ProgramLocations>
<Term>201210</Term>
</ProgramList>
<ProgramList>
<AreaOfInterests xmlns:a="http://schemas.datacontract.org/2004/07/Taca">
<a:AreaOfInterest>
<a:Interest>GRADUATE CERTIFICATE STUDIES</a:Interest>
</a:AreaOfInterest>
<a:AreaOfInterest>
<a:Interest>HEALTH AND WELLNESS STUDIES</a:Interest>
</a:AreaOfInterest>
</AreaOfInterests>
<Coop>false</Coop>
<MajorDescription>ADVANCED CARE PARAMEDIC</MajorDescription>
<Program>PARM</Program>
<ProgramLocations>
<ProgramLocation>
<Campus>Barrie</Campus>
</ProgramLocation>
</ProgramLocations>
<Term>201210</Term>
</ProgramList>
</ArrayOfProgramList>
他のSOの質問でXMLをソートする最も簡単な方法を読んだので、SimpleDOMでそれをやろうとしています。
私は使用してみました:
foreach($listxml->sortedXPath('//ArrayOfProgramList/ProgramList','//ArrayOfProgramList/ProgramList/MajorDescription') as $program){ ... }
および「@MajorDescription」、「/MajorDescription」、「.」などの他の同様の「並べ替え」値。ここで提案されているように、SimpleDOM sortedXPath を使用してノード値でソートするにはどうすればよいですか? しかし、 var_dump() でチェックすると、すべてが空の配列を返します
問題は、子ノードの値でソートする必要があることだと思います-これは可能ですか? 各反復で ProgramList 内のすべての子ノードの値を出力する必要があるため、foreach は ProgramList 上にある必要があります。
助言がありますか?SimpleDOM を使用する必要はありません。動作する任意の方法を受け入れます。現在、AZ の配列を反復処理し、文字ごとに ProgramList を反復処理し、MajorDescription の最初の文字を現在の文字と比較して、一致する場合は出力します-これは明らかに理想的ではなく、最初の文字のみをソートします...