Log in

View Full Version : as posted elseware



ajfmrf
08-30-2011, 06:24 PM
As posted elseware by james 348 I believe:



<?php
$my_array = array('home', 'member', 'join', 'login', 'news');
$ret=implode(' | ',$my_array);
echo $ret;
?>


How would I assign urls to the links.

(please keep in mind I am a newbie with php...)

Bud

bluewalrus
08-30-2011, 06:55 PM
Do you mean...


<?php
$my_array = array('<a href="index.php">home</a>', '<a href="user.php">member</a>', '<a href="join.php">join</a>', '<a href="login.php">login</a>', '<a href="news.php">news</a>');
$ret=implode(' | ',$my_array);
echo $ret;
?>

If not please be more specific.

jscheuer1
08-30-2011, 07:51 PM
Or perhaps a bit confusing, but space/keystroke saving:


<?php
$my_array = array('index.php">home', 'user.php">member', 'join.php">join', 'login.php">login', 'news.php">news');
$ret = '<a href="' . implode('</a> | <a href="', $my_array) . '</a>';
echo $ret;
?>

If you used the text as keys and the href values as their values, you do foreach on it. If I work that out, I'll add it.

Got it:


<?php
$my_array = array(
'home' => 'index.php',
'member' => 'user.php',
'join' => 'join.php',
'login' => 'login.php',
'news' => 'news.php'
);
$c = count($my_array);
foreach($my_array as $key => $val){
echo "<a href='$val'>$key</a>";
if(--$c){echo ' | ';}
}
?>

ajfmrf
08-30-2011, 08:14 PM
I was getting close to what you both have.Not there yet but inching there.

Thanks to both of you .

Bud