echo two variables on the one line

Discussion in 'PHP' started by oo7ml, Oct 1, 2007.

  1. #1
    Hi, i have a page that echoes my username at the top of the page, however i want to change it to firstname lastname

    At the top of the page the following code appears:

    <? echo $_SESSION['user_info']['username'];?>


    however my firstname and lastname are the following variables. How do output the two of these with just the one echo

    firstname = $_SESSION['my_array'][1]
    lastname = $_SESSION['my_array'][12]
     
    oo7ml, Oct 1, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    <?php
    
    echo $_SESSION['my_array'][1], ' ', $_SESSION['my_array'][12];
    
    ?>
    
    PHP:
     
    nico_swd, Oct 1, 2007 IP
  3. oo7ml

    oo7ml Well-Known Member

    Messages:
    656
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #3
    should there be single or double quotes between them
     
    oo7ml, Oct 1, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    No difference as there are no variables between them.
     
    nico_swd, Oct 1, 2007 IP
  5. oo7ml

    oo7ml Well-Known Member

    Messages:
    656
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #5
    Ok, thanks for your help
     
    oo7ml, Oct 1, 2007 IP
  6. volumedrive

    volumedrive Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You could also do:

    echo 'First: ' . $_SESSION['my_array'][1] . 'Last ' . $_SESSION['my_array'][12];
     
    volumedrive, Oct 1, 2007 IP
  7. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #7
    Is that who you output names? :D

    Besides, you are missing a space.
     
    krt, Oct 1, 2007 IP