merge array problem

Discussion in 'PHP' started by bumbar, Jan 18, 2013.

  1. #1
    Hello,

    I have 2 array:

    
    $pids = array ( 40 => 0, 41 => 1, 43 => 2, 42 => 3 );
    
    $ids = array( $pids , 678=>'', 444=>''); 
    
    PHP:
    I want to join the two arrays.
    How do I get the following output in the second array:

    $result = array (40 => '', 41 => '', 43 =>'', 42 => '', 678=>'', 444=>'');

    Thank you!
     
    bumbar, Jan 18, 2013 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    
    $array = array_merge(array_keys($pids), array_keys($ids));
    
    PHP:
    like this?
     
    EricBruggema, Jan 18, 2013 IP
  3. DrShirts

    DrShirts Peon

    Messages:
    28
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    1
    #3
    
    <?php
    $array1 = array("color" => "red", 2, 4);
    $array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", 4);
    $result = array_merge($array1, $array2);
    print_r($result);
    ?>
    
    Code (markup):
     
    DrShirts, Jan 20, 2013 IP