PHP和simplexml

i use php and simplexml, my probleme is "to add a attribute with for" my code is:

for($i=1;$i<=$compteur;$i++)
    {
        $jeu->situation->question->choix->addChild('rep',"
".$rep[$i]."
");
        $jeu->situation->question->choix->rep->addAttribute('val',$i);

    }

Result:

                             <choix>
                <rep val="1">

                </rep>
                <rep>

                </rep>
            </choix>

he add just in a first !!!

addChild() returns the node that was added to the DOM, so do your attribute work on that

$child = $jeu->situation->question->choix->addChild('rep',"
".$rep[$i]."
");
$child->addAttribute('val', $i);