How to Merge Two Arrays in PHP?

Posted by

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours scrolling social media and waste money on things we forget, but won’t spend 30 minutes a day earning certifications that can change our lives.
Master in DevOps, SRE, DevSecOps & MLOps by DevOps School!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

I explained simply how to merge two arrays in PHP Laravel. you will learn how to append two arrays in PHP. you will learn how to merge multiple arrays in PHP. you will do the following things for php merge two array example. We will use the array_merge() function and + sign to merge multiple arrays in PHP. I will give you simple two examples.

Example 1:

<?php
  
    $arrayOne = ["One", "Two", "Three"];
    $arrayTwo = ["Four", "Five"];
        
    $newArray = array_merge($arrayOne, $arrayTwo);
    
    var_dump($newArray);
  
?>

Output: 1

Example: 2

<?php
  
    $arrayOne = [1 => "One", 2 => "Two", 3 => "Three"];
    $arrayTwo = [4 => "Four", 5 => "Five"];
        
    $newArray = $arrayOne + $arrayTwo;
    
    var_dump($newArray);
  
?>

Output: 2

Leave a Reply

Your email address will not be published. Required fields are marked *

0
Would love your thoughts, please comment.x
()
x