Your code should trigger a clear error message with debug information:
Notice: Array to string conversion
... on this line:
echo explode('.', 'a.b');
... and finally print this:
Array
I suppose you would not ignore this helpful information if you'd seen it so you've probably haven't configured your PHP development box to display error messages. The simplest way is, when installing PHP, to get your php.ini
file by copying php.ini-development
instead of php.ini-production
. If you are using a third-party build, just tweak the error_reporting
and display_errors
directives.
As about the error, you have to understand that arrays are complex data structures, not scalar values. You cannot print an array as-is with echo
. In the development phase you can inspect it with var_dump()
(like any other variable).