Dev Diaries WD logo Dev Diaries WD
PHP INTERVIEW · EP 04
PHP INTERVIEW · Episode 04

What’s the difference between array_combine() and array_merge()?

Two very different ways to put arrays together

ep4_array_combine_and_merge.php
<?php
// Your code will go here.
$fruitsOne = ["Mangoe" , "Bananas" , "Orange"];
$fruitsTwo = ["Pineapple" , "Watermelon","Litchi"];

$mergedArray = array_merge($fruitsOne , $fruitsTwo);
$comoinedArray = array_combine($fruitsOne , $fruitsTwo);
Output
Output for this tutorial goes here.

Show the actual printed result of the code above.

Array merge output =

Array
(
    [0] => Mangoe
    [1] => Bananas
    [2] => Orange
    [3] => Pineapple
    [4] => Watermelon
    [5] => Litchi
)
        

Array combine output =

Array
(
    [Mangoe] => Pineapple
    [Bananas] => Watermelon
    [Orange] => Litchi
)
        

Watch the full episode

Watch on YouTube