Results 1 to 3 of 3

Thread: How to generate something like 'this' from this array? i'm really confusing :'(

  1. #1
    Join Date
    Aug 2008
    Location
    karanganyar, solo, indonesia
    Posts
    161
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question How to generate something like 'this' from this array? i'm really confusing :'(

    i have an array

    PHP Code:
    $my_array = array('home''member''join''login''news'); 
    i want to make like below

    home | member | join | login| news


    i have tried the below code
    PHP Code:
    <?php
    $my_array 
    = array('home''member''join''login''news');
    $ret '';
    foreach(
    $my_array as $item){
        
    $ret .= $item.' | ';
    }
    echo 
    $ret;
    ?>
    UNFORTUNATELY it displays:
    home | member | join | login | news |

    CAN somebody help?
    ///////////////////////////////////////////////////
    ///// http://www.mediatutorial.web.id
    ///////////////////////////////////////////////////

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,692
    Thanks
    82
    Thanked 90 Times in 88 Posts

    Default

    PHP Code:
    <?php 
    $my_array 
    = array('home''member''join''login''news'); 
    $ret=implode(' | ',$my_array);
    echo 
    $ret
    ?>
    Last edited by james438; 08-29-2011 at 10:22 AM. Reason: oops, didn't add the spaces
    To choose the lesser of two evils is still to choose evil. My personal site

  3. #3
    Join Date
    Aug 2008
    Location
    karanganyar, solo, indonesia
    Posts
    161
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Wink

    thanks so much,
    it simple and works
    ///////////////////////////////////////////////////
    ///// http://www.mediatutorial.web.id
    ///////////////////////////////////////////////////

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •