私は約60冊の本を含むxmlファイルを持っています.phpを使って借りた数から昇順にする必要があります.これまでのところ私のコードはすべての本を表示していますが、ソートしません どんな助けでも本当に感謝します
PHP
<?php
$xmlassignDoc = new DOMDocument();
$xmlassignDoc->load("books.xml");
$books = $xmlBookDoc->getElementsByTagName("item");
foreach($books as $list)
{
$course = $list->getElementsByTagName("course");
$course = $course->item(0)->nodeValue;
//HERE is where the GET function will be
if ($course == "CC150")
{
print_r($array);
$id = $list->getAttribute("id");
echo "<b>Book ID: </b> $id <br>";
$title = $list->getElementsByTagName("title");
$title = $title->item(0)->nodeValue;
echo "<b>Title: </b> $title <br>";
$isbn = $list->getElementsByTagName("isbn");
$isbn = $isbn->item(0)->nodeValue;
echo "<b>ISBN: </b> $isbn <br>";
$borrowed = $list->getElementsByTagName("borrowedcount");
$borrowed = $borrowed->item(0)->nodeValue;
echo "<b>Borrowed Count: </b> $borrowed <br>";
echo "<br>";
}
}
//print $xmlBookDoc->saveXML();
?>
xml ファイル
<?xml version="1.0" encoding="utf-8"?>
<bookcollection>
<items>
<item id="51390">
<title>Management of systems development /</title>
<isbn>0091653215</isbn>
<url>http://library.hud.ac.uk/catlink/bib/51390</url>
<borrowedcount>45</borrowedcount>
<courses>
<course>CC140</course>
<course>CC210</course>
</courses>
</item>
<item id="483">
<title>Database systems management and design /</title>
<isbn>0877091153</isbn>
<url>http://library.hud.ac.uk/catlink/bib/483</url>
<borrowedcount>28</borrowedcount>
<courses>
<course>CC140</course>
</courses>
</item>
<item id="585842">
<title>E-learning skills /</title>
<isbn>0230573126</isbn>
<url>http://library.hud.ac.uk/catlink/bib/585842</url>
<borrowedcount>5</borrowedcount>
<courses>
<course>CC157</course>
</courses>
</item>