php - Formatting double quotes string with functions -
i trying learn write more advanced strings. know using 3 different statements, such:
<?php function1(); echo " | "; function2(); ?> to result this: result1 | result2
(my real world example creating links previous , next posts in wordpress, such as:
<?php previous_post_link( '%link', '< previous' ); echo ' | '; next_post_link( '%link', 'next >' ); ?> )
but, since trying improve, , learn new things, trying write more cleanly. know can use double quotes , curly brackets insert functions, this:
<?php echo "{${function1()}} | {${function2()}}"; ?> but returns result this: result1result2 |
why happen , how can write code correctly?
thanks!
this because of logic "clean" example proceeded php. steps are:
- invoke function1(). function makes immediate output screen: "result1"
- invoke function2(). functions makes immediate output screen: "result2". , have "result1result2" on screen
- concatenate returned value of function1(), " | ", , returned value of function2(), , echo concatenated string. returned values null, assume, functions not use return statements. so, output step " | ".
- finally, have "result1result2 | "
Comments
Post a Comment