0

I've just came across this post mentioning that echo can only print string(s), that's why we cannot print the full array. But, we can easily echo integers and floats etc like this:

$int = 3;  $float = 3.456;  
echo $int, "</br>", $float;

I was just wondering does echo cast these variables to string type behind the scenes?

Thank you.

user31782
  • 7,087
  • 14
  • 68
  • 143
  • 1
    Not sure if there is a fuller answer (a duplicate) but `echo` will try and convert any parameter to a string - objects will have the `__toString()` method called (if there is one). – Nigel Ren Dec 28 '19 at 11:35
  • @NigelRen Would you be able to provide any reference like something from the php manual. – user31782 Dec 28 '19 at 11:49

1 Answers1

2

Per the section on Converting to string from the manual:

String conversion is automatically done in the scope of an expression where a string is needed. This happens when using the echo or print functions, or when a variable is compared to a string.

Jeto
  • 14,596
  • 2
  • 32
  • 46