Combine two arrays using Php

PHP array_merge() Function

The array_merge() function merges one or more arrays into one array.

Syntax
array_merge(array_1, array_2)
Example:
<?php
    $a1=array("apple","banana");
    $a2=array("watermelon","pineapple");
        print_r($a1);
    echo "<br>";
    print_r($a2);
    echo "<br>";
    print_r(array_merge($a1,$a2));
?>

output:
Array ( [0] => apple [1] => banana )
Array ( [0] => watermelon [1] => pineapple )
Array ( [0] => apple [1] => banana [2] => watermelon [3] => pineapple )


                                                                                                                    - Happy Coding

Comments

Popular posts from this blog

Validation Code For Phone Number Using preg_match() in Php

Writing data to a file using Python

Simple HTML Form Elements For Registration Page Example