Combine array in laravel in the blade file example

In this tutorial, I will give you an example of a How to Combine array in laravel in the blade file, So you can easily apply it with your laravel 5, laravel 6, laravel 7, laravel 8, and laravel 9 application.

First, what we’re doing here, This is the example :

Combine array in laravel in the blade file example

We will combine two arrays using the PHP array_combine() Function.

PHP array_combine() Function

The array_combine() function creates an array by using the elements from one “keys” array and one “values” array.

Note:– Both arrays must have an equal number of elements.


array_combine(keys, values)


Combine array in foreach loop in Laravel Blade file


<!DOCTYPE html>
<html lang="en">
      <title>combine two array in laravel foreach loop</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet" href="">
      <script src=""></script>
      <script src=""></script>
   <div class="container">
         <h2 style="color: #BE206B;">Combine Array's in foreach loop in the Blade File | Laravel</h2>
         $user_names = array('John','David','Sachin','Gaurav');
         $user_emails = array('','','','');

         <table class="table table-bordered">
            @foreach (array_combine($user_names, $user_emails) as $user_name => $user_email) 
                  <td>{{ $user_name ?? '' }}</td>
                  <td>{{ $user_email ?? '' }}</td>

Related article:- Get data from two models in Laravel.

combine array in laravel in blade file example

In this article, we learned merge two arrays in laravel or laravel combine two arrays example, I hope this article will help you with your Laravel application Project.

Read also:- Access application in maintenance mode using a secret token in Laravel.

Hi, My name is Gaurav Pandey. I'm a Laravel developer, owner of 8Bityard. I live in Uttarakhand - India and I love to write tutorials and tips that can help other developers. I am a big fan of PHP, Javascript, JQuery, Laravel, WordPress.

Scroll to Top