开发者

How to display a return value on the browser?

I have the following inside a function something():

if ($cod == 1000)
{
  $message = 'Some Message';
  return $message;
}

Later, I call this function:

try
{
   $comandoController->someThing();
}

I was expecting to see "Some Message" on th开发者_StackOverflowe browser. But I don't.

Note: If I echo something like echo "hello" inside the conditional, I can see it. So the condition is the case.

Instead of $comandoController->someThing(); should we do the following:

$result = $comandoController->someThing(); 
echo $result; 


Works as designed. This

try
{
   $comandoController->someThing();
}

will not output anything to the browser. The return value can be echoed:

echo  $comandoController->someThing();

or stored:

$value =  $comandoController->someThing();

but as it stands, no browser output will take place.


You need to echo that:

echo $comandoController->someThing();

Or use the echo inside your function instead:

if ($cod == 1000)
{
  echo 'Some Message';
}

Now you simply need to do:

$comandoController->someThing();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜