I would like to know how to make a list of links appear on my page displaying a name but when you click it, it navigates to the link.
I currently know how to make a list and display the items of it using the foreach command and arrays but is there a way I can make it so I have an array, containing an array, containing the name of the link and the link itself, like so:
$links = array(array("Google","//google.co.uk"),array("Bing","//bing.co.uk"))
foreach ($links as $myurl){
foreach ($myurl as $url){
echo "<a href='".$url."'>".$myurl."</a>";
}};
I know the above doesn't work but if anyone can help with this problem, it is much appreciated.
$links = array('Google' => 'www.google.com', 'Yahoo' => 'www.yahoo.com');
foreach($links as $k => $v) {
echo '<a href="//' . $k . '">' . $v . '</a>';
}
As you can see I don't specify http
or https
, just //
works on both! See: http://google-styleguide.googlecode.com/svn/trunk/htmlcssguide.xml
You can add links to $links
with:
$links['stackoverflow'] = 'www.stackoverflow.com';
$links = array(
array("Google","//google.co.uk"),
array("Bing","//bing.co.uk")
);
foreach ($links as $urlitem){
echo "<a href='".$urlitem[1]."'>".$urlitem[0]."</a>";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With