php

How to merge multiple arrays into one array in PHP

In this tutorial, we are going to see how to merge multiple arrays into one array in PHP. You can use PHP’s array_merge() function to merge the elements or values of two or more arrays into one array. Merging occurs so that the values of an array are added to the end of the previous array.
 

How to merge multiple arrays into one array in PHP
<?php
	$languages = array("PHP", "Java", "Python", "HTML", "CSS", "JavaScript");
	$skills = array("Developer", "Designer", "Architect", "Consultant");
	 
	// Merge the two arrays
	$merge = array_merge($languages, $skills);
	print_r($merge);
?>

Output:

Array (
	 [0] => PHP 
	 [1] => Java 
	 [2] => Python 
	 [3] => HTML 
	 [4] => CSS 
	 [5] => JavaScript 
	 [6] => Developer 
	 [7] => Designer 
	 [8] => Architect 
	 [9] => Consultant 
)

 

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

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