0
如何獲得陣列數據我在XML SPARQL輸出是這樣的:`從XML環的foreach
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
<head>
<variable name="Keyword2"/>
</head>
<results ordered="false" distinct="false">
<result>
<binding name="Keyword2">
<uri>http://www.semanticweb.org/g/ontologies/2010/0/OntologiBatikTanty#Soga_Jawa</uri>
</binding>
</result>
<result>
<binding name="Keyword2">
<uri>http://www.semanticweb.org/g/ontologies/2010/0/OntologiBatikTanty#Warna_Alami</uri>
</binding>
</result>
</results>
</sparql>
`
我做的foreach循環在php這樣的:`
$xml = simplexml_load_string($hasil) or die ("error cannot create object");
$results = $xml->results->result;
$jumlah=count($results);
echo "Total hasil pencarian : $jumlah <br><br>";
//$keyword2=array();
$output=array();
foreach($xml->results->result as $nodes){
$jumlah=count($nodes);
foreach ($nodes->binding as $key =>$node) {
$output=$node->uri;
echo $output;
echo "<br><br>";
echo $keyword=substr($output,66);
echo "<br><br>";
}
}
echo"<hr>";
echo $keyword[0];
`
我的問題是如何從外部循環訪問數據數組。例如我想訪問索引[0]。但只輸出「W」應該是「Soga_Jawa」
我可以幫助你,你能以更好,更清晰的方式向我解釋你的問題 –
[如何使用PHP和XML的foreach(simplexml)]的可能重複(https://stackoverflow.com/questions/4637617/how-to- use-foreach-with-php-xml-simplexml) –
@Nirajpatel thank y OU。你的代碼運行良好。 – Tanty