Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Combine two arrays - one for key and another for value

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 109
    Comment on it

    Hello friends,

    If you want to combine 2 arrays in which 1 is used as a key and another as value then you can use a predefined PHP function which is "array_combine". array_combine function creates an array by using one array for keys and another for its values.

    Here is an example which is explaining this-

    <?php
    $a = array('key1', 'key2', 'key3');
    $b = array('value1', 'value2', 'value3');
    $c = array_combine($a, $b);
    
    print_r($c);
    ?>
    

    Output:

    Array
    (
        [key1]  => value1
        [key2]    => value2
        [key3] => value3
    )
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: