0

Actually I can't understand how I will explain my problem. I am trying to give an example. In my php code I got a array like this:

Array ( [0] => E-mail [1] => Newsletter )

I want to retrieve all the value from this array & want to store it in $result. I tried with foreach function. But I can't store all the result in $result as because it's changing each time & printing separate value. Anyone can help me please. Thanks in advance.

6
  • What is wrong with $result = Array( [0] => E-mail [1] => Newsletter ) ? Commented Jun 15, 2013 at 19:37
  • Thanks, Actually I want to print the value of $result but output will be like this E-mail, Newsletter. Commented Jun 15, 2013 at 19:40
  • Post your code please. Where did that "Array ( [0] => E-mail [1] => Newsletter )" came from? From a var_dump() or a print_r or what? Commented Jun 15, 2013 at 19:43
  • foreach ($data1 as $k => $v) { $result .= $v; } echo $result; It's working just fine. But showing output like this E-mailNewsletter. Can I put a , between Email & Newsletter. I want like this: E-mail,Newsletter. Commented Jun 15, 2013 at 19:44
  • Do you want to convert array to string, actually? php.net/manual/en/function.implode.php Commented Jun 15, 2013 at 19:47

1 Answer 1

1
foreach ($array as $k => $v) {
    $result .= $v;
}

echo $result;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks it will work but do you know how I will insert , between the result. You code output will be like this E-mailNewsletter. But I want to be E-mail,Newsletter. Actually I want to insert extra html tag also. Like <p>

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.