开发者

How can create function like this in PHP? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be 开发者_运维技巧reopened, visit the help center. Closed 11 years ago.

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜