[help need] Array Linking

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [help need] Array Linking

    Well, this thing is confusing me lot. What I need to do is just extracting data from an array and want to put a clickable link with variable. Like this:
    PHP Code:
    Array
     (
         [
    a] => apple
         
    [b] => banana
         
    [c] => orange
      
    )

    to <a href="?data=orange">orange</a
    all I end up is this:
    PHP Code:
    for ($i 0$i count($fruit); ++$i) { print "<a href='?data=".$fruit[$i]."'>".$fruit[$i]."</a>"; } 
    I want a comma if there is a second fruit out there. But if I put this
    PHP Code:
    foreach ($fruit as $key => $val) {
        print 
    "<a href='?data=$val'>$val</a>, ";

    it just put the , (comma) after all fruit.
    Can anyone please tell me how to make it right?
    Last edited by asifnayem; 09.11.12, 17:21.

    #2
    PHP Code:
    <?
    $fruit = array('apple', 'banana', 'orange', 'mango');
    $c = count($fruit);
    for ($i=0; $i < $c; $i++) { 
        echo $fruit[$i];
        if ($i != $c-1) {
            echo ", ";
        }
        else {
            echo ".";
        }
    }
    This may give you some ideas
    I need some facebook likes, can you please help me
    http://facebook.com/softwarefreakin
    I noticed social media is really powerful
    Well DONE is better than well SAID

    Comment

    Working...
    X