SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Join 2 array

  1. #1
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I know ways to join the arrays, but pretty ugly, prefer an optimized function of PHP. So the question is:

    Is there a function for joining 2 array? and is it in PHP4 or PHP3?

    Thanks
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Son

    array_merge() is what you are looking for I believe. Its a PHP4 function
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm currently on a PHP3 server, so any function like array_xx is unsupported!!! Thanks Freddy, have to ask for PHP4 now
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is of course the long way to do it

    for($i=0;$i<count($array2);$i++) {
    $array1[count($array1)] = $array2[$i];
    }
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    Non-Member
    Join Date
    Apr 2000
    Location
    Waco, Texas.
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Freddy, is there a reason why you use:
    '$array1[count($array1)]'?

    I tried
    Code:
        $foo = array(1,2);
        $bar = array(3,4);
        for($i=0;$i<=count($bar);$i++)
        {
             $foo[] = $bar[$i];
        }
        //$foo now '1234'
    seems to work fine for me.

  6. #6
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's the same thing Rob,
    since every time you add a new entry, the call to count($array1) will increase by one, so it will always at the end.
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  7. #7
    Non-Member
    Join Date
    Apr 2000
    Location
    Waco, Texas.
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I understand this, which is why I asked. It just seems a little inefficient do add the extra code?

  8. #8
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Probably so I didn't have time to test and I just wanted make sure that the additions were gettiong the correct indexes
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •