problem on retrieve data from XML into PHP

one text

i retrieve the data from XML file successfully and save it into array, i would like to use stored array on other scope of code how? please have a look at my code:

<?php
$path = DIR_LANGUAGE."register.xml";
$xml=simplexml_load_file($path) or die("Error: Cannot load language file");
foreach($xml->children() as $register) {    
       $index = (int)$register->name['index'];
       $value = $register->valen;
       $data = array_fill($index,1,$value);
       echo $data[$index];
       echo "<br>";
}
echo $data[$index];
?>

the echo command inside for each work fine, but not that one outside foreach

how can i use the data array outside code and even on other PHP file?

Source