if you have a line of text in an array, you can join it all together to form a single line of text. This is just the opposite of explode. This time, use implode( ):
$seasons = array("Autumn", "Winter", "Spring", "Summer");
$new_textline = implode( ",", $seasons );
$new_textline = implode( ",", $seasons );
Here we have an array called $seasons. The text in the array needs to be joined before writing it back to a text file. The implode( ) function does the joining. The syntax for the implode( ) function is just the same as explode( ).
implode( separator, text_to_join )
So implode( ) will join all the text together and separate each part with a comma, in the code above. Of course, you don't have to use a comma. You could use a dash:
$new_textline = implode("-", $seasons)
Or any other character:
$new_textline = implode("#", $seasons)
Even a space:
$new_textline = implode( " ", $seasons)
The implode( ) function can come in handy, if you need to work with single lines of text.
No comments:
Post a Comment