Skip to content

Instantly share code, notes, and snippets.

@Sstobo
Created November 7, 2017 17:58
Show Gist options
  • Select an option

  • Save Sstobo/7e38fcae185efdd967fb05d0093363b5 to your computer and use it in GitHub Desktop.

Select an option

Save Sstobo/7e38fcae185efdd967fb05d0093363b5 to your computer and use it in GitHub Desktop.
[PHP array implode explode] #php
To convert array items into a comma-separated string, use the implode() function:
$skills = array( 'html', 'css', 'js', 'php' );
$comma_separated = implode(',', $array);
echo $comma_separated; // output: html,css,js,php
You can also convert a string to an array using the explode() function:
$skills = 'html css js php';
$skills_array = explode( ' ', $skills );
print_r( $skills_array );
// output: Array ( [0] => html [1] => css [2] => js [3] => php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment