Array to string conversion laravel Controller

You can use implode method for conversion from array to string in the laravel controller. implode() method is a build-in method which is used to create a string from an array. Just use this method inside your controller method.

Answers 3
  • Input array to comma separated string conversion in laravel controller

    <form action="{{ route('store') }}" method="post">
        <input type="text" name="email[]"/>
        <input type="text" name="email[]"/>
        <button type="submit"> Submit </button>
    public function inputArrayToString(Request $request){
        $string = implode(',', $request->email);
        echo $string;
        //perform task after converting input array to string

    This code snippet is used to convert the input array to a comma-separated string using the controller method. Create routes in web.php and change the routes name as per your requirement.

  • Array to string conversion laravel blade

    --PATH resources\views\<home>.blade.php
        $array = array('This','is','a','string');   
        $string = implode(" ",$array); 
        echo $string; 
    //Output :
    This is a string

    You can convert an array to string using implode method in laravel view.

  • Implode() method example in php

    	$array = array('This','is','a','string');
    	$string = implode(" ",$array);
    	echo $string;
    //This is a string

    This method converts an array value to a string value. It takes two parameters, the first is the separator and the second is the array value which we have to convert into a string.

  • Back to code snippet queries related laravel