php - Why does the "echo" statement support outputting multiple arguments in a single line and the "echo" function does not?
Get the solution ↓↓↓In PHP you can output multiple arguments at once with theecho
statement like this:
echo "Mangoes", " ", "are", " ", "tasty.";
When you try to do the same with theecho
function like this:
echo("Mangoes", " ", "are", " ", "tasty.");
You get a error, why is this so?
Could this be because PHP wants you to use string concatenation instead of multiple arguments?
Thank you in advance.
Answer
Solution:
Because is not a function. The docs clearly state this:
echo is not actually a function (it is a language construct), so you are not required to use parentheses with it. echo (unlike some other language constructs) does not behave like a function, so it cannot always be used in the context of a function. Additionally, if you want to pass more than one parameter to echo, the parameters must not be enclosed within parentheses.
Answer
Solution:
when you callecho()
its mean you call the function ofecho()
. The echo just has one parameterecho(_string_)
. SO when you include the , sign in the bracket of echo parameter, so it means you make echo function has more than one parameter. So you are not allowed to do like thisecho("Mangoes", " ", "are", " ", "tasty.");
Please see this http://www.w3schools.com/php/func_string_echo.asp
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: to enable extensions, verify that they are enabled in your .ini files
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.