如何以这种格式使用php获取外部文件的xml数组
$locations = array(
(Bondi Beach, -33.890542, 151.274856, 4),
(Coogee Beach, -33.923036, 151.259052, 5),
(Cronulla Beach', -34.028249, 151.157507, 3)
);
//this is my file php
$dom = new DOMDocument();
$dom->load('school.xml');
$students = $dom->getElementsByTagName('student');
$i = 0;
foreach ($students as $student) {
$locations = $students->item(0)->nodeValue;
echo $locations;
$i++;
}
当我运行此代码时,返回以下结果:
Bondi Beach -33.890542 151.274856 4 Coogee Beach -33.923036 151.259052 5 Cronulla Beach -34.028249 151.157507 3
我必须进行哪些更改才能返回具有以下格式的数组?:
这是我的数组 school.xml
<school>
<student>
<name>Bondi Beanch</name>
<latitude>-33.890542</latitude>
<longitude>151.274856</longitude>
<id>4</id>
</student>
<student>
<name>Coogee Beach</name>
<latitude>-33.923036</latitude>
<longitude>151.259052</longitude>
<id>5</id>
</student>
<student>
<name>Cronulla Beach</name>
<latitude>-34.028249</latitude>
<longitude>151.157507</longitude>
<id>3</id>
</student>
</school>