1

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?

1
  • I've changed your tags: Added 'php' and 'array' tags. And not sure what your question had to do with MySQL, so removed that. Commented May 18, 2011 at 15:34

2 Answers 2

3

Depending on how your array is organized, you could do

x = implode(',',$two_dimensional_array['index1']);
Sign up to request clarification or add additional context in comments.

Comments

1

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;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.