Why am I printing in this order?

Asked

Viewed 36 times

1

<?php
function foo($var){
 echo $var + 3;
}
$x = 1;

echo "foo($x) =".foo($x);
?>

I was watching some exercises in php,then I came across the code, thinking I was going to print foo(1) = 4, but printed 4foo(1) =.

Why am I calling the job foo($x) before the string of echo? He believed that the code would follow the normal 'stream' of the line and first print the string and only after that would call the function foo($x).

In my interpretation, where am I missing? Or php has some particularity?

1 answer

3


You’re making a echo printing and not a return in function foo.

<?php
function foo($var){
 return $var + 3;
}
$x = 1;

echo "foo($x) =".foo($x);
?>
  • Wow! Truth, what inattention, I went unnoticed and I messed up with Return, thank you very much!!! Once the site free minino time to accept the answer, valid your

Browser other questions tagged

You are not signed in. Login or sign up in order to post.