开发者

How to do an if statement on a function in PHP?

开发者 https://www.devze.com 2022-12-20 15:36 出处:网络
I just realized that you can\'t just use an if statement on a function, for example this doesn\'t work:

I just realized that you can't just use an if statement on a function, for example this doesn't work:

function sayHello()
{
    echo "Hello World";
}

if(sayHello())
    echo "Function Worked";
else
    echo "Function Failed";

I also saw that a function can't be put as the value o开发者_如何学Cf a variable. So how can I do an if statement to check if a function has executed properly and display it to the browser?


It's not working since sayHello() doesn't return anything place return true in there or something.


if (sayHello() === FALSE)
    echo "Function Failed";
else
    echo "Function Worked";


this will work

<?php

$name1 = "bobi";

function hello($name) {
if($name == "bobi"){
    echo "Hello Bob";
  } else {
      echo "Morning";
    }
}

hello($name1);
?>


function selam($isim)
{
    if ($isim == 'ugur') {
        return 'Selam '.$isim.' :)';
    }

    return 'Sen kimsin kardes?';
}

echo selam('ugur');
0

精彩评论

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