Jenny
Jenny

Reputation: 1727

How to make this array flat?

I have an array, some elements are single string, final element is comma seperated string

Array (
    [0] => text 
    [1] => text 
    [2] => text
    [3] => text1, text2, text3
 )

I want to join all elements into one comma seperated string. Neither explode nor join could manage this. How can I get a result like this:

array(text, text, text, text1, text2, text3)

Upvotes: 3

Views: 763

Answers (3)

Headshota
Headshota

Reputation: 21439

You can use implode:

implode(",", $array);

Upvotes: 1

scessor
scessor

Reputation: 16115

$aNew = array(implode(', ', $aTest));

Also see this or this example.

Upvotes: 2

Shakti Singh
Shakti Singh

Reputation: 86406

implode it and then explode

$array = explode(',', implode(',', $array));

Upvotes: 2

Related Questions