Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array to String PHP?

Tags:

arrays

string

php

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

like image 794
Philip Kirkbride Avatar asked Sep 20 '11 19:09

Philip Kirkbride


People also ask

What is implode () in PHP?

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.

What is the name of the function used to convert an array into a string?

Using implode() , you can turn the array into a string.

How do I convert an array of numbers to strings?

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.


1 Answers

Use implode

implode("|",$type); 
like image 56
Niet the Dark Absol Avatar answered Oct 02 '22 09:10

Niet the Dark Absol