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


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);


        $string2 = 'LARAVEL';

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


Laravel Arr wrap function output

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



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 :  Laravel Carbon Get Tomorrow Date Example