Arr::crossJoin() laravel helper function will help to make cross the array of each key and values of key of each index.
Using this Arr::crossJoin() function array will cross each key's and value.
Sometime developer need to make cross the array.
Here below example using laravel helper function array, crossJoin function the array make cross into each key's and value.
This Arr::crossJoin() in laravel function crossjoin the given arrays and returning a certesian product with all prossible permutations.
<?php use Illuminate\Support\Facades\Route; use Arr; /* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */ Route::get('/arr-collapse', function () { // Example 1 $matrix = Arr::crossJoin([1, 2], ['a', 'b']); /* [ [1, 'a'], [1, 'b'], [2, 'a'], [2, 'b'], ] */ // Example 2 $matrix = Arr::crossJoin([1, 2], ['a', 'b'], ['I', 'II']); /* [ [1, 'a', 'I'], [1, 'a', 'II'], [1, 'b', 'I'], [1, 'b', 'II'], [2, 'a', 'I'], [2, 'a', 'II'], [2, 'b', 'I'], [2, 'b', 'II'], ] */ });
Please follow the above example and apply in your laravel application.
We always thanks to you for reading our blogs.
![dharmesh-image](/storage/site-setting/w4q23X3ihxZ9MQ5o4GeFthb0mqCcg4LgG8sIqigI.png)
Dharmesh Chauhan
(Swapinfoway Founder)Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us
![haresh-image](/storage/site-setting/uESEBDJrsDNffCSc0uNtilcThH7Y0df7oI93WCPP.png)
Haresh Chauhan
(Co-Founder)We Are Also Recommending You :
- Laravel One to Many Eloquent Relationship Tutorial With Example
- Laravel 10 Sanctum API Authentication Tutorial Example
- Laravel Postcodes
- Error : Array to string conversion Laravel
- How To Configuration Laravel Supervisor
- REST API Authentication With Laravel Passport - Webappfix
- [issue] Possible All Way To Change Asset Path And Add Public To Asset Path In Laravel
- Laravel Remove index.php From URL
- How To Insert Current Datetime In Database Laravel
- Laravel Carbon diffForHumans Arguments Passing