1

Here is simple line of code:

echo $array2[3]."<br>";

The . Operator is appending <br> with array resulting into the following error:

Array to string conversion

I don't want to use {$array2[3]} like that. Is there any way to put both things in echo seperated?

Edit: Is there any way to print array with Echo

Mark Evans
  • 974
  • 1
  • 11
  • 29

1 Answers1

3

Use implode on your array with your desired delimiter.

echo implode("<br />", $yourArray);

As mentioned in the comments it's advised to use <br /> instead of <br> when you want' to use the echo inside a web application.

If you want to debug the array it's better to use print_r() or var_dump().

cb0
  • 8,415
  • 9
  • 52
  • 80
  • Why is it better to use `
    `?
    – likeitlikeit Jun 18 '13 at 11:54
  • Depending on what you output. In HTML, the
    tag has no end tag. In XHTML, the
    tag must be properly closed, like this:
    . Also have a look [here](http://stackoverflow.com/questions/1946426/html-5-is-it-br-br-or-br) for further informations.
    – cb0 Jun 18 '13 at 12:32
  • That means, `
    ` will work whatever the document type? Cool, thanks!
    – likeitlikeit Jun 18 '13 at 14:05