This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Functions, Part I Forum

View Course

461 points
525d8bedabf82129b10018f2_245969237
Submitted by
Josh
almost 3 years ago

Print and echo?

What is the different between echo and print? And when should i use echo and when should i use print?


66 votes

permalink

You can give multiple strings to echo:

echo "This", " string", " was", " made", " with multiple parameters.";

though print can take only one string:

print "This", " string", " was", " made", " with multiple parameters.";
// gives error

echo is marginally faster as compared to print.


print returns 1.

print (print "");
// gives `1` since the inner `print` returned 1 
// which the outer `print` printed

echo does not return anything.


I recommend using echo than print.

That's all to it :)

2570 points
56ec11ba1ec4b00bc400069e_656519138
Submitted by
Gaurang Tandon
almost 3 years ago

5 Comments

522a6f84548c354fe10003da_800546975 gh0zt almost 3 years ago

Thanks for the answer I was wondering this too.

525d8bedabf82129b10018f2_245969237 Josh almost 3 years ago

oh thank you!

557ede39d3292f7a0000006a_306960922 wolfie almost 3 years ago

What is print_r(); Can anyone please say? When we use it?

F6f4cd3ba4d981baf0edd3972fa27050?s=140&d=retro Dennis Castro Alonzo about 2 years ago

thanks!


13 votes

permalink

echo() and print() are language constructs in PHP, both are used to output strings. The speed of both statements is almost the same.

echo() can take multiple expressions whereas print cannot take multiple expressions.

Print return true or false based on success or failure whereas echo doesn't return true or false.

324 points
53e36f7080ff3323f3001439_510830465
Submitted by
Rias Gremory
almost 3 years ago


8 votes

permalink

Basically, when you echo something, you can say lots of things to output. Such as if you were to shout into a cave and hear it ECHO.

Where as printing can only print one thing or expression. Much like a document you print. You can only PRINT the one document, before asking to print another. ;) HOPE THIS HELPED

216 points
528246b680ff3393e0003430_637958903
Submitted by
Nathaniel
about 2 years ago


-18 votes

permalink

please check help my site: fxpro

77 points
7b7eba4bdaeb13f88b2d42ac38bcb8b5?s=140&d=retro
Submitted by
truong12
over 2 years ago


-90 votes

permalink

do it yourself stop getting the answers

59 points
D948cb4caf6ebbeac094d5c5f5e3ae23?s=140&d=retro
Submitted by
michael festekjian
over 2 years ago

5 Comments

Picture Samuel Martin over 2 years ago

Do what, exactly?

528246b680ff3393e0003430_637958903 Nathaniel over 2 years ago

Find out the difference? I don't know. Maybe that kid has problems....

54d5899686f5521e68003b7b_714393002 MurtazaSadeq about 2 years ago

Do not discourage anyone while they are learning!

54c12e1d9113cb4e8e00209f_576201493 Gouthamm Guru about 2 years ago

Then what are you doing in the forum page?

1fd1601a6654f4f1164c8bc7b19f2358?s=140&d=retro Bryan almost 2 years ago

^