user391986
user391986

Reputation: 30926

php explode on two dimensional array

I have a two dimensional array in php and I want to get the second dimension (index 1) as a list of values seperated by a comma. Do I have to write my own custom functions or can I use some variation of explode on two dimensional arrays?

Upvotes: 1

Views: 1845

Answers (2)

Cobra_Fast
Cobra_Fast

Reputation: 16111

First of all, your are looking for implode() and not for explode().

function flatten($two_dim_array)
{
     $result = array();
     foreach ($two_dim_array as $array)
          $result[] = implode("," $array);
     return $result;
}

Upvotes: 1

Amy Anuszewski
Amy Anuszewski

Reputation: 1853

Depending on how your array is organized, you could do

x = implode(',',$two_dimensional_array['index1']);

Upvotes: 3

Related Questions