SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    midnight coder
    Join Date
    Dec 2000
    Location
    The flat edge of the world
    Posts
    838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a little piece of code like this:

    PHP Code:
    <?

        $i
    ="1";
        while(
    $i<=$n)
            {
            
    $nid "nid$i";
            
    $mark "mark$i";
            
    $valuearray[] =  "('" $eid "','" . $$nid "','" . $$mark "'),";
            
    $i++;
            }

        foreach (
    $valuearray as $value)
            {
            echo 
    "$value";
            }
    ?>
    And it gives me something like:

    ('SB5000','1','21'),('SB5000','2','22'),('SB5000','3','23'),('SB5000','4','24'),

    Which is what I want. But how do I save that output string as a variable? So if I was to go "echo $newvalue;", it would give me the string as the foreach() did?
    Last edited by Robo; Apr 29, 2001 at 17:54.

  2. #2
    SitePoint Zealot DarkMonkey's Avatar
    Join Date
    Apr 2001
    Location
    uk
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I understand the problem correctly. then this should work

    PHP Code:
        foreach ($valuearray as $value)
            {
            
    $newvalue .= $value;
            }
    echo 
    $newvalue

  3. #3
    midnight coder
    Join Date
    Dec 2000
    Location
    The flat edge of the world
    Posts
    838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, that worked

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is a built in function to do this:
    string implode (string glue, array pieces)
    http://www.php.net/manual/en/function.implode.php

    $valueString = implode("", $valueArray);


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
  •