Logical Operators Without If in PHP Functions
Let's say we have a function with an if statement. Here it is:
<?php
function func($a, $b) {
if ($a > $b) {
return true;
} else {
return false;
}
}
?>
As you already know from previous lessons,
if
constructs that return boolean values
can be rewritten in a shortened form.
Let's do this:
<?php
function func($a, $b) {
return $a > $b;
}
?>
Given the following function:
<?php
function func($a, $b) {
if ($a === $b) {
return true;
} else {
return false;
}
}
?>
Rewrite its code in a shortened form according to the studied theory.
Given the following function:
<?php
function func($a, $b) {
if ($a !== $b) {
return true;
} else {
return false;
}
}
?>
Rewrite its code in a shortened form according to the studied theory.
Given the following function:
<?php
function func($a, $b) {
if ($a + $b >= 10) {
return true;
} else {
return false;
}
}
?>
Rewrite its code in a shortened form according to the studied theory.
Given the following function:
<?php
function func($num) {
if ($num >= 0) {
return true;
} else {
return false;
}
}
?>
Rewrite its code in a shortened form according to the studied theory.