What is the best method for converting a PHP array into a string?
I have the variable $type
which is an array of types.
$type = $_POST[type];
I want to store it as a single string in my database with each entry separated by |
:
Sports|Festivals|Other
The 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.
Using implode() , you can turn the array into a string.
To convert an array of numbers to an array of strings, call the map() method on the array, and on each iteration, convert the number to a string. The map method will return a new array containing only strings.
Use implode
implode("|",$type);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With