DEV Community

Cover image for Uses of array_combine function
Istiaq Nirab
Istiaq Nirab

Posted on

Uses of array_combine function

array_combine is a inbuilt Function in PHP .

These function creates an array by using the elements from one keys array and one values array.

Example

<?php
    $a = array('green', 'red', 'yellow');
    $b = array('avocado', 'apple', 'banana');
    $c = array_combine($a, $b);

    print_r($c);
?>
Enter fullscreen mode Exit fullscreen mode

Result

Array
(
    [green]  => avocado
    [red]    => apple
    [yellow] => banana

)
Enter fullscreen mode Exit fullscreen mode

Thanks

Top comments (0)