Array to string conversion 🐘 PHP

Warning: Array to string conversion

An array was used where a string is expected — echoing it, concatenating it, or passing it to a string function.

Seen on: PHP

Meaning

PHP prints the literal word “Array”. Often a form field submitted as an array (name="tags[]"), a function returning an array, or debug output with echo instead of print_r.

Common causes

  • echo $array or "text $array"
  • Form field with [] in its name
  • Function returned an array where you expected a string
  • Passing an array to htmlspecialchars/strlen

⚡ Quick fix

  1. Use implode(', ', $array) to join
  2. Use print_r/var_dump/json_encode for debugging
  3. Check form field names

Detailed fix by platform

PHP

  1. echo htmlspecialchars(implode(', ', (array) $_POST['tags']));

How to diagnose

  1. Value — var_dump() it — what does the array contain?
  2. Intent — Join, pick one element, or encode?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.