some php ARRAY help please

Discussion in 'PHP' started by JEET, Aug 8, 2007.

  1. #1
    Hi,
    I got 2 arrays, like this:

    array1{
    [0] => a1v1
    [1] => a1v2
    }

    array2{
    [0] => a2v1
    [1] => a2v2
    }

    Now what I need to do is make a new array using values of the 2 arrays above.

    The values of "first" array will be "keys", and values of "second" array will be "values of keys" respectively.

    I know how to do this in PHP5, but need this on PHP4

    php5 code:
    
    <?php
    $newarray= array_combine(array1,array2);
    ?>
    
    Code (markup):
    Any idea how to do this?
    Thankyou :)
     
    JEET, Aug 8, 2007 IP
  2. mrburns

    mrburns Peon

    Messages:
    9
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    How about

    for($n=0;$n<count($array1);$n++)
    {
    $key=$array1[$n];
    $newarray[$key]=$array2[$n];

    }
     
    mrburns, Aug 8, 2007 IP
    JEET likes this.
  3. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #3
    Hi,
    Thanks :) Works perfect.
    Green reputation added.
    Bye :)
     
    JEET, Aug 8, 2007 IP