Im having trouble setting a variable as part of a function, im sure its down the syntax more than anything, what im trying to do is use a if/else statement and as part of it, to return a variable $Bname.
But im not sure how to set it.
My function is as follows
function bestPriceFunc($var1, $var2) {
if ($var1 < $var2) {
return $var1;
$Bname = 'will';
return $Bname;
} else {
return $var2;
$Bname = 'Lad';
return $Bname;
}
}
is this the correct way to do it or could i just write return $Bname = 'Lad';. Ive tried both but i getting an undefined variable error when i load the page
You can only use return once per function as it terminates the function the first time it is executed.
Try the following or if you don’t need to return $var1 and $var2, simply remove those lines.