How to solve PHP error ‘Notice: Array to string conversion in…’?

Spread the love

Sometimes, we want to solve PHP error ‘Notice: Array to string conversion in…’.

In this article, we’ll look at how to solve PHP error ‘Notice: Array to string conversion in…’.

How to solve PHP error ‘Notice: Array to string conversion in…’?

To solve PHP error ‘Notice: Array to string conversion in…’, we should make sure we aren’t trying to use print or echo on an array.

For instance, instead of using echo or print, we write

$stuff = [1, 2, 3];
print_r($stuff);

$stuff = [3, 4, 5];
var_dump($stuff);

to call print_r or var_dump with an array variable to print its contents.

Trying to print the contents of an array with print or echo will result in an error with PHP 7.x./

Conclusion

To solve PHP error ‘Notice: Array to string conversion in…’, we should make sure we aren’t trying to use print or echo on an array.

Leave a Reply

Your email address will not be published.