如何传递for循环处理的数组中的所有值?

How to pass all the values in an array which is processed by for loop?

<?php

    $xml = simplexml_load_file("sample.xml");

    echo " ". $xml->getName() . "<br />";

    foreach($xml->children()->children() as $child)

      {

      $a=$child->getName() . "<br />";
        array_push($a);
        echo $a;

      }

?> 

试试这个

<?php
    $arr = array();        
    $xml = simplexml_load_file("sample.xml");

    echo " ". $xml->getName() . "<br />";

    foreach($xml->children()->children() as $child)
    {
        $a=$child->getName() . "<br />";
        $arr[] = $a;
        echo $a;
    }
?>