Reputation: 70
I have parsed many differend xml to check, if - for example - a document is online or not and putting it into an array and "echo" the online documents this way:
<?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.;
}
}
?>
Now here is the interesting part of my question. I would like to link each array with a different URL like this:
<?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.;
}
}
?>
Any suggestions are welcome!
Upvotes: 0
Views: 65
Reputation: 198203
Create a composite for each entry, the first exemplary:
$externdoc[123] = array("Example 1", 'http://www.example.com/docs/1.php');
Inside the foreach you can then refer to the title and the URL:
foreach($externdoc as $nr => $entry)
{
list($name, $url) = $entry; # name and URL in a variable of it's own
...
Hope this is helpful, this is basically to create an array Docs of arrays. Instead of using one array per entry/item, you can also use stdClass
objects Docs which can have multiple properties as well (like an array can have multiple key/value pairs).
Upvotes: 1