In this tutorial you will learn about the Laravel Arr wrap() function Example and its application with practical example.
Laravel Arr wrap() function Example
In this article, I’ll show you how to use laravel Arr wrap() function with example. We will show example of Arr wrap() function in laravel. In this tutorial, we will use Arr wrap() function to convert string variable to array.
Laravel Arr::wrap method
The Arr::wrap method converts or wraps the given value in an array format. If the given value is already an array format it will be returned without modification.
Example:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Controllers\FileController; use Illuminate\Support\Arr; class HomeController extends Controller { /** * Show the application dashboard. * * @return \Illuminate\Contracts\Support\Renderable */ public function index() { $string1 = 'steve'; $array1 = Arr::wrap($string1); print_r($array1); echo "<br>"; $string2 = 'laravel'; $array2 = Arr::wrap($string2); print_r($array2); } } |
Output:-
1 2 |
Array ( [0] => steve ) Array ( [0] => laravel ) |