Array to string conversion PHP Origin: Application & API Last updated 13 Oct 2026

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.

Exact message you may see Array to string conversion
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 not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

Cannot convert value of type — Swift: Cannot convert value of type 'X' to expected argument type 'Y' (iOS)Cannot convert value …Cannot use object as array — Fatal error: Uncaught Error: Cannot use object of type stdClass as array (PHP)Cannot use object as …ClassCastException — java.lang.ClassCastException: class A cannot be cast to class B (Java)ClassCastExceptionComposer memory — Composer: PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (PHP)Composer memoryE0308 — Rust: error[E0308]: mismatched types — expected `X`, found `Y` (Rust)E0308ERR_INVALID_ARG_TYPE — TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined (Node.js)ERR_INVALID_ARG_TYPEImplicit float to int — Deprecated: Implicit conversion from float 2.5 to int loses precision (PHP)Implicit float to intPrimary script unknown — FastCGI sent in stderr: "Primary script unknown" (PHP)Primary script unknownArray to …

Explore the map of this error Full error map →

🧠 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.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.