Convert array to string php w3schools
❮ PHP String Reference Show
ExampleJoin array elements with a string: $arr = array('Hello','World!','Beautiful','Day!'); Try it Yourself » Definition and UsageThe implode() function returns a string from the elements of an array. Note: The implode() function accept its parameters in either order. However, for consistency with explode(), you should use the documented order of arguments. Note: The separator parameter of implode() is optional. However, it is recommended to always use two parameters for backwards compatibility. Note: This function is binary-safe. SyntaxParameter Values
Technical Details
More ExamplesExampleSeparate the array elements with different characters: $arr = array('Hello','World!','Beautiful','Day!'); Try it Yourself » ❮ PHP String Reference ❮ PHP String Reference ExampleBreak a string into an array: $str = "Hello world. It's a beautiful day."; Try it Yourself » Definition and UsageThe explode() function breaks a string into an array. Note: The "separator" parameter cannot be an empty string. Note: This function is binary-safe. Syntaxexplode(separator,string,limit) Parameter Values
Technical Details
More ExamplesExampleUsing the limit parameter to return a number of array elements: $str = 'one,two,three,four'; // zero limit // positive limit // negative limit Try it Yourself » ❮ PHP String Reference (PHP 4, PHP 5, PHP 7, PHP 8) implode — Join array elements with a string Descriptionimplode(string Alternative signature (not supported with named arguments): implode(array
Legacy signature (deprecated as of PHP 7.4.0, removed as of PHP 8.0.0): implode(array Parametersseparator Optional. Defaults to an empty string. array The array of strings to implode. Return ValuesReturns a string containing a string representation of all the array elements in the same order, with the separator string between each element. Changelog
ExamplesExample #1 implode() example
= ['lastname', 'email', 'phone']; Notes
See Also
houston_roadrunner at yahoo dot com ¶ 13 years ago
"a1 is: '".implode("','",$a1)."' biziclop ¶ 1 year ago
wrap_implode(['path','to','file.php'], '/'); ASchmidt at Anamera dot net ¶ 3 years ago
implode( ',', $a ),'/', implode( ',', $b ); omar dot ajoue at kekanto dot com ¶ 9 years ago
= array('a', 'b', 'c'); Honk der Hase ¶ 2 years ago
mapped_implode(', ', $arr, ' is ');// output: x is 5, y is 7, z is 99, hello is World, 7 is Foo?>
Felix Rauch ¶ 6 years ago
__construct($title) alexey dot klimko at gmail dot com ¶ 11 years ago
Anonymous ¶ 9 years ago
masterandujar ¶ 10 years ago
Anonymous ¶ 7 years ago
Rafael Pereira ¶ 2 years ago
admin at lanlink dot net dot au ¶ 5 years ago
info at ensostudio dot ru ¶ 2 years ago
a' => 1, 'b' => 2]; info AT sinistercircuits DOT com ¶ 10 months ago
How do I turn an array into a string in PHP?There are two ways to convert an array into a string in PHP.. Using implode() function.. Using json_encode() function.. What is implode () in PHP?The implode() function in PHP is called “array to a string,” as it takes an array of elements and returns a string. For example, if we want to join an array of elements to form one string, we can use the implode() function to perform the same.
What are the uses of explode () and implode () functions?While explode() function is used to output an array by breaking apart a string with the help of another string, the implode() function is used to output a string by joining the elements(strings) of an array with the help of another string.
What is Str_split function in PHP?The str_split() is an inbuilt function in PHP and is used to convert the given string into an array. This function basically splits the given string into smaller strings of length specified by the user and stores them in an array and returns the array.
|