Debug ProblemsLearn to code with Laravel | Laravel Resource Centre

Array to string conversion error in php

Are you having this error Array to string conversion in your code? Here is how to fix it.

Array to string conversion

What you’re doing wrong

Actually, the error itself is self-explaining, somewhere in your code, you are trying to convert an array to a string. Here is an example

$data = ['John','Mike','Mary'];

echo $data;

As you can see in the example above, when I try to echo a variable ($data) that holds an array of strings, I get the error

Error Exception Array to string conversion

Solution to

A simple solution will be to replace echo with var_dump.


Follow this article to learn more on how echo works in php.

Related Articles

Leave a Reply

Your email address will not be published.

Back to top button