Today, We want to share with you array to string conversion laravel.In this post we will show you array to string conversion php, hear for array to string conversion in php mysql we will give you demo and example for implement.In this post, we will learn about How to String Replace in PHP Functions? with an example.
array to string conversion laravel json
Example 1:
You can use php implode for this or you can also use laravel collection for this. heres the exmaple
collect([8, 9, 3, 4, 5])->implode('-'); // '8-9-3-4-5'
$player_info = array('Welcome','Pakainfo!','Sejal','Baka!'); echo implode(" ",$player_info); //Welcome Pakainfo! Sejal Baka!
Example 2:
print_r($request->player_info); //It is an array print $player_info_json = json_encode($request->player_info); //array to json string conversion echo $player_info_json; // printing json string print_r(json_decode($player_info_json)); //printing array after convert json string to array exit; // exiting further execution to check resutls
Example 3: using implode() function
$collection = collect([ ['alexa_rank' => 1, 'website' => '4cgandhi'], ['alexa_rank' => 2, 'website' => 'infinityknow'], ]); $collection->implode('website', ', '); // 4cgandhi, infinityknow
Array to String Conversion in PHP
php Array to string conversion
Example 2:
Using implode() function in Php
//Syntax implode(separator,array); //Example //Output: infinityknow pakainfo, Virat Kohali !
Array to String Conversion in PHP
$website_list = array( 'infinityknow', 'pakainfo', 'w3school' ); echo implode($website_list);
array to string conversion in php
$website_list = [ 'name' => 'infinityknow', 'age' => 5, 'status' => null, 'niche' => ['SEO', 'Laravel', 'Angularjs'] ]; echo json_encode($website_list); // {"name":"infinityknow","age":5,"status":null,"niche":["SEO","Laravel","Angularjs"]}
I hope you get an idea about multidimensional array to string php.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.