J'ai fais ainsi afin d'avoir un tableau qui comporte tous les commentaires qu'on trouve dans des fichiers xml :
<?
$arrayComment = array();
$users = $xpUsers->query('//user[@active="1"]');
for ($i=0; $i<$users->length; $i++) {
$idUser = $users->item($i)->getAttribute('id');
$userReportingFile = $cfg['ressources_root'].'/reporting/'.$idUser.'.xml';
if ( is_file($userReportingFile) ) {
//on ouvre le fichier
$domUserReportingFile = new DOMDocument('1.0','UTF-8');
$domUserReportingFile->load($userReportingFile);
$xpUserReportingFile = new DOMXPath($domUserReportingFile);
$commentUser = $xpUserReportingFile->query('//comment');
for ($j=0; $j<$commentUser->length; $j++) {
$dateComment = $commentUser->item($j)->getAttribute('date');
$comment = $commentUser->item($j)->nodeValue;
//echo $dateComment." : ".$comment;
$arrayComment[$idUser]['date'] = $dateComment;
$arrayComment[$idUser]['comment'] = $comment;
echo "<pre>"; print_r($arrayComment); echo "</pre>";
}
}
}
?>
Le ^problème, c'est qu'en faisant ainsi, j'obtiens : Code : Tout sélectionner
Array
(
[1] => Array
(
[date] => 09-08-2007
[comment] => more and more information.
)
)
Array
(
[1] => Array
(
[date] => 05-08-2007
[comment] => bad practice. Too in brief.
)
)
Code : Tout sélectionner
Array
(
[1] => Array
(
[date] => 09-08-2007
[comment] => more and more information.
)
[2] => Array
(
[date] => 05-08-2007
[comment] => bad practice. Too in brief.
)
)