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:

  1. invoke function1(). function makes immediate output screen: "result1"
  2. invoke function2(). functions makes immediate output screen: "result2". , have "result1result2" on screen
  3. concatenate returned value of function1(), " | ", , returned value of function2(), , echo concatenated string. returned values null, assume, functions not use return statements. so, output step " | ".
  4. finally, have "result1result2 | "

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -