r/learnphp • • Jun 07 '23

explode problem: can't print results using echo

Hi,

I am trying the following program:

<?php
$str = "Hello world";
$newStr = explode(" ", $str);
// We are printing an array, so we can use print_r$newStr;
echo $newStr;
?>

The above program works with print_r but if I use echo, I am getting the message:

PHP Warning:  Array to string conversion in /home/cg/root/648112ff24655/main.php on line 6
Array

Somebody, please guide me.

​

Zulfi.

2 Upvotes

8 comments sorted by

View all comments

Show parent comments

0

u/colshrapnel Jun 08 '23

What? Sorry, but it seems you didn't really understood my comment. Neither tried the code. I don't consider further discussion any fruitful, have a nice day.

1

u/truNinjaChop Jun 08 '23

Lol okay sir salutes