I'm tried to parse XML response with DOM.
<GetBilletResult>
<sNomProduit>product 2</sNomProduit>
<sNomArticle>article 4</sNomArticle>
...
<tabGrilleHoraire>
<tabDetailTarifArticle>
<tabDetail>
<sDetail>Liste Pax : Pax n°1 [Âge:19]</sDetail>
<sAgePax>19;</sAgePax>
...
</tabDetail>
</tabDetailTarifArticle>
...
<tabGrilleHoraire>
</GetBilletResult>
I need to reorder the result and regroup the articles by products. The output should look like this :
sNomProduit : product 2
sNomArticle : article 1
-
tabGrilleHoraire
- tabDetailTarifArticle
- tabDetail
- sDetail : Liste Pax : Pax n°1 [Âge:19]
- sAgePax : 19;
- tabDetail
- tabDetailTarifArticle
Working code (thanks to ConstantineUA) :
$processed = array();
foreach( $billets as $GetBilletResult )
{
$sNomProduit = $GetBilletResult->getElementsByTagName( "sNomProduit" )->item(0)->nodeValue;
$nIDProduit = $GetBilletResult->getElementsByTagName( "nIDProduit" )->item(0)->nodeValue;
$sNomArticle = $GetBilletResult->getElementsByTagName( "sNomArticle" )->item(0)->nodeValue;
$nIDArticle = $GetBilletResult->getElementsByTagName( "nIDArticle" )->item(0)->nodeValue;
$tabDetail = $GetBilletResult->getElementsByTagName( "tabDetail" );
if (!isset($processed[$sNomProduit])) {
$processed[$sNomProduit] = array();
}
$processed[$sNomProduit][] = array(
'nIDProduit' => $nIDProduit,
'sNomArticle' => $sNomArticle,
'nIDArticle' => $nIDArticle,
'tabDetail' => $tabDetail,
);
}
Loop:
foreach ($processed as $sNomProduit => $list) {
echo "<h3> ".$sNomProduit."</h3>";
foreach ($list as $item) {
echo "<h5> ".$item['sNomArticle'] . "</h5>";
foreach ($item['tabDetail'] as $node) {
var_dump ($node->nodeValue);
}
}
echo "<hr>";
}