
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
The easiest way to concatenate two arrays in PHP?
Simply use, array_merge() to concatenate two arrays in PHP. Let’s say the following are out arrays −
$nameArray1 = array('John','David'); $nameArray2 = array('Mike','Sam');
Now, set both the above arrays in array_merge() to concatenate them.
The syntax is as follows −
array_merge($yourFirstArrayName, $yourSecondArrayName);
Example
The PHP code is as follows
<!DOCTYPE html> <html> <body> <?php $nameArray1 = array('John','David'); $nameArray2 = array('Mike','Sam'); $result = array_merge($nameArray1, $nameArray2); print_r($result); ?> </body> </html>
Output
This will produce the following output
Array ( [0] => John [1] => David [2] => Mike [3] => Sam )
- Related Articles
- How to concatenate two arrays in java?
- How to concatenate Two Arrays in C#?
- Java Program to Concatenate Two Arrays
- The easiest way to insert date records in MySQL?
- Easiest way to sort an array in MongoDB
- How can I concatenate two arrays in java
- How to express the number16000 in exponential form in the easiest way?
- What is the easiest way to store date in MySQL database?
- What is the easiest way to reverse a String in Java?
- What is the easiest way to convert int to string in C++
- What is the easiest way to lose weight without exercise?
- What is the easiest way to transfer files from phone to PC?
- Easiest way to get number of rows in a MySQL table?
- Merging two arrays in a unique way in JavaScript
- What is the easiest way to convert a List to a Set in Java?

Advertisements