-1

I tested below code:

printf("I am %s.", 'cool');

Output: I am cool.

And then I added, echo with printf:

echo printf("I am %s.",'cool');

Output: I am cool.10

What is this 10? I changed values and this suffixed number kept on changing. Can anyone tell me what is happening here? I am just curious. Does this code has any significance or this is just a weird behavior I should forget?

Deepak
  • 35
  • 7
  • 3
    Possible duplicate of [Reference: Comparing PHP's print and echo](https://stackoverflow.com/questions/7094118/reference-comparing-phps-print-and-echo) – Amadeu Antunes Feb 18 '19 at 05:06
  • 3
    Hint: count the number of characters in the string, or if you don't want to guess, read the manuals return values http://php.net/printf – Qirel Feb 18 '19 at 05:09

1 Answers1

1

printf() prints the given string format as it is and Returns the length of the outputted string. that's why you are getting it's return value when you use echo with printf function you can get your output directly by using printf() hope you will get the answer

Please read this

Amadeu Antunes
  • 678
  • 1
  • 8
  • 28
Asad
  • 124
  • 1
  • 9