How can create function like this in PHP? [closed]
I want to create function like this. please help me to complete my function if both are +ve
$a = 10;
$b = 6;
// do nothing just show same value 10 and 6
// if $b is negetive
$a = 10;
$b = -3;
// get the value from $a show the value 7 (10 - 3)
// 0 if $a is negative
$a = -2;
$b = 6;
// (little bit diffrent) get the double form $b of negative value and
// show the value 0 and 2(6-4)
i have tried with this but totally stopped at else code
// $a = something;
// $b = something;
if ($a >0 && $b >0) {
echo $a.' , '.$b;
}else{
// what? what? what?
}
Something along the lines of
<?php
if ($a > 0) {
if ($b > 0) echo $a." ".$b;
else echo ($a+$b)." 0";
}
else {
if ($b > 0) echo "0 ".($b+$a*2);
//else undefined?
}
?>
Looks a bit homeworky though
精彩评论