Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

problem with if statement used to determine function return

Im using an if statement to determine what to return in a function, but it seems to be not working the way i want it to.

function DoThis($dogs, $cats){
// do something with dogs, pet them perhaps.

$reg = $dogs[0];
$nate = $dogs[1];

if($cats = "dave"){return $reg;}
if($cats = "tom"){return $nate;}

}

$cats is a string (if that helps), and when entered it doesn't yield any return. If i manually set a return, that works, but the above doesnt for some reason.

like image 360
mrpatg Avatar asked Nov 18 '25 20:11

mrpatg


1 Answers

To test for equality, use the == (double equals) operator instead of the = (single equals) operator.

For example:

if("dave" == $cats){return $reg;}
if("tom"  == $cats){return $nate;}
like image 57
Justin Ethier Avatar answered Nov 20 '25 12:11

Justin Ethier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!