+ 2

Echo print

Why this code prints 31? Echo print 3; It prints 3 because of the echo and then 1 because echo is true? Thank you.

11th Aug 2018, 9:33 PM
razvan
razvan - avatar
4 ответов
+ 3
razvan , print $some_arg; prints value of $some_arg and as function returns 1. so function always_one in code bellow always return 1: function always_one(){ return print 25; } echo always_one(); #the output will be: #251 because print 25; output 25 and return 1, which will be output in echo statement... Sorry for my English if I wrote with errors in grammatic
19th Aug 2018, 10:46 PM
Dmitriy
Dmitriy - avatar
+ 3
i believe so. "print 3" prints 3 and then echo just prints the result of that which is 1. php is just like that sometimes
11th Aug 2018, 9:43 PM
hinanawi
hinanawi - avatar
+ 2
i think it is because print always prints 1 so in this example echo will output 3 and then print will output 1.
11th Aug 2018, 9:54 PM
razvan
razvan - avatar
+ 2
thank you for the explanaition.
11th Aug 2018, 9:54 PM
razvan
razvan - avatar