close

How to convert array to string in laravel?

Hello Guys, How are you all? Hope You all Are Fine. Today we are talking about How to convert array to string in laravel? in php. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How to convert array to string in laravel Error Occurs?

Today we are talking about How to convert array to string in laravel? in php.

How To Solve convert array to string in laravel Error ?

  1. How To Solve convert array to string in laravel Error ?

    To Solve convert array to string in laravel Error You can use php implode for this or you can also use laravel collection for this. heres the exmaple

  2. How to convert array to string in laravel?

    To Solve convert array to string in laravel Error You can use php implode for this or you can also use laravel collection for this. heres the exmaple

Solution 1

easy way is using json_encode and json_decode php functions.

if you want to store an array in string column you can use:

$adprofile->education = json_encode($array);

and if you want to get that from DB and convert it back to an array use:

$array = json_decode($adprofile->education);

Solution 2

You can use php implode for this or you can also use laravel collection for this. heres the exmaple

collect([1, 2, 3, 4, 5])->implode('-');

// '1-2-3-4-5'

see documentation for this Implode

or you can use php function implode

see this

$arr = array('Hello','World!','Beautiful','Day!');
echo implode(" ",$arr);
//Hello World! Beautiful Day!

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment