php array to string : Today, We want to share with you array to string.In this post we will show you array to string conversion error foreach, hear for array to string with keys we will give you demo and example for implement.In this post, we will learn about php array. with an example.
php array to string
Example : 1 PHP implode() Function
Example : 2 How to convert array to string in PHP ?
"PAKA", array( "email"=>"[email protected]", "mobile"=>"XXXXXXXXXX" ) ); // Use json_encode() function $json = json_encode($value); // Display the output echo($json); ?>
Example : 3 Convert PHP Array to String using implode()
Convert PHP Associative Array to String using implode()
$members = [ 'member1' => '[email protected]', 'member2' => '[email protected]' ]; echo implode(', ',$members); // "[email protected], [email protected]"
Combine both Index and value to string
$members = [ 'member1' => '[email protected]', 'member2' => '[email protected]' ]; $flattened = $array; array_walk($flattened, function(&$value, $key) { $value = "{$key}:{$value}"; }); echo implode(', ', $flattened); // "member1:[email protected], member2:[email protected]"
Convert PHP Array to String using json_encode() and serialize()
1) json_encode()
$arr = ['Baka','Manager India','Virat Kohali']; echo json_encode($arr); // "['Baka','Manager India','Virat Kohali']"
2) serialize()
$arr = ['Baka','Manager India','Virat Kohali']; echo serialize($arr); // a:3:{i:0;s:4:"Baka";i:1;s:15:"Manager India";i:2;s:8:"Virat Kohali";}
I hope you get an idea about php array to string.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.