Laravel Arr wrap() function Example

In this example, I will show how to use laravel Arr wrap() function. Laravel Arr wrap() function is use to convert string variable to array.

Array wrap() function example

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\User;
use Illuminate\Support\Arr;

class UserController extends Controller
{
    public function index(){        
        $string1 = 'Car';

        $array1 = Arr::wrap($string1);

        print_r($array1);
        //['car']

        $string2 = 'LARAVEL';

        $array2 = Arr::wrap($string2);

        print_r($array2);
        //['LARAVEL']
    }
}

Laravel Arr wrap function output

Array ( [0] => Car ) 
Array ( [0] => LARAVEL )

routes/web.php

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;

Route::get('users', [UserController::class,'index']);

I hope you understand of laravel array wrap function and it can help you…

Read Also :  How to Get App Directory Path in Laravel