我已经解析了许多不同的xml来检查,如果-例如-文档是否在线,并将其放入数组并以这种方式"回显"在线文档:
<?php
//
//Array
$externdoc[123] = "Example 1";
$externdoc[456] = "Example 2";
$externdoc[789] = "Example 3";
$externdoc[2562] = "Example 4";
$externdoc[78545] = "Example 5";
// func
foreach($externdoc as $nr => $name)
{
$xml = simplexml_load_file("http://www.example.com/docs.php?live_id=".$nr);
if($xml->liveDocs->download!=0)
{
echo 'Download: '. $xml->liveDocs->download.' '.$name.;
}
}
?>
现在是我的问题中有趣的部分。我想链接每个数组与不同的URL,像这样:
<?php
//
//Array
$externdoc[123] = "Example 1";
$externdoc [url] = 'http://www.example.com/docs/1.php';
$externdoc[456] = "Example 2";
$externdoc [url] = 'http://www.example.com/docs/2.php';
$externdoc[789] = "Example 3";
$externdoc [url] = 'http://www.example.com/docs/3.php';
$externdoc[2562] = "Example 4";
$externdoc [url] = 'http://www.example.com/docs/4.php';
$externdoc[78545] = "Example 5";
$externdoc [url] = 'http://www.example.com/docs/5.php';
// func
foreach($externdoc as $nr => $name)
{
$xml = simplexml_load_file("http://www.example.com/docs.php?live_id=".$nr);
if($xml->liveDocs->download!=0)
{
echo '<a href="HOW DO I LINK IT?"> Download: '. $xml->liveDocs->download.' '.$name.;
}
}
?>
欢迎提出任何建议!
为每个条目创建一个组合,第一个示例:
$externdoc[123] = array("Example 1", 'http://www.example.com/docs/1.php');
在foreach中,你可以引用标题和 URL:
foreach($externdoc as $nr => $entry)
{
list($name, $url) = $entry; # name and URL in a variable of it's own
...
希望这是有帮助的,这基本上是创建一个数组Docs数组。你也可以使用stdClass
对象Docs,它也可以有多个属性(就像数组可以有多个键/值对一样)。