joining two arrays together

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • petermichaux@yahoo.com

    joining two arrays together

    Hi,

    I would like to join two arrays togther something like the following. I
    don't know a simple way to create $stack3.

    Thanks,
    Peter

    <?php

    $stack1 = array("orange", "banana");
    $stack2 = array("apple", "pear");

    // do what for the next line?
    $stack3 = ($stack1, $stack2);

    print_r($stack3 );
    // The results I would like
    // Array ( [0] => orange [1] => banana [2] => apple [3] => pear )

    ?>

  • Joachim Weiß

    #2
    Re: joining two arrays together

    petermichaux@ya hoo.com schrieb:[color=blue]
    > $stack1 = array("orange", "banana");
    > $stack2 = array("apple", "pear");
    >
    > // do what for the next line?
    > $stack3 = array_merge($st ack1, $stack2);
    >[/color]

    Jo

    Comment

    • romain.jouin@gmail.com

      #3
      Re: joining two arrays together

      if you have two similar keys in an associative array, you will have
      problems : the values for one key is deleted by the values of the
      ultimate similar key (see doc!).

      Comment

      • Joachim Weiß

        #4
        Re: joining two arrays together

        romain.jouin@gm ail.com schrieb:[color=blue]
        > if you have two similar keys in an associative array, you will have
        > problems : the values for one key is deleted by the values of the
        > ultimate similar key (see doc!).
        >[/color]
        your're right, but for the fuits in the example it works.
        if you have similar keys you need your own function
        because nobody knows what to do with those keys ...

        ignore the first, discard the second, generate a new key, add the values
        ...

        Jo

        Comment

        • ZeldorBlat

          #5
          Re: joining two arrays together

          $stack3 = array_merge($st ack1, $stack2);

          Comment

          Working...