Results 1 to 6 of 6

Thread: How do I turn an array into a string?

  1. #1
    Join Date
    Feb 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How do I turn an array into a string?

    hi all,

    Can you please tell me how do I turn an array into a string?

    Thanks
    Last edited by Twey; 02-11-2009 at 12:03 PM. Reason: Signature.

  2. #2
    Join Date
    Feb 2009
    Posts
    73
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    PHP not like C/C++

    String in PHP doesn't consist of array of char like C

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Using implode().
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Feb 2009
    Posts
    73
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    This is the example :

    <?php

    $array = array('lastname', 'email', 'phone');
    $comma_separated = implode(",", $array);

    echo $comma_separated; // lastname,email,phone

    ?>
    Yeah, good idea.

    Btw, what is the diffrence between explode and strtok?
    Thanks

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Quite a lot.

    Code:
    $str = "foo\nbar\tbaz\n\tquux";
    
    explode("\n\t", $str); // array("foo\nbar\tbaz", 'quux');
    
    strtok($str, "\n\t"); // 'foo'
    strtok("\n\t"); // 'bar'
    strtok("\n\t"); // 'baz'
    strtok("\n\t"); // 'quux'
    strtok("\n\t"); // false
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Feb 2009
    Posts
    73
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    nice...
    thanks, I've learnt from you

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
  •