1. Re-write the ternary operator to if/else:
echo ( $widgets >= 10 ) ? $plenty : $few;
Ans:
if( $widgets >= 10)
echo "$plenty.";
else
echo "$few.";
2. Re-write the if/else to a ternary operator:
if($score >= 70)
echo "You pass the course.
";
else
echo "You have to retake the course.
";
Ans:
$passed = "You pass the course.
";
$failed = "You have to retake the course.
";
echo ( $score >= 70 ) ? $passed : $failed;
3. Re-write the ternary operator to if/else:
echo "$x is an ". ($x%2 == 0 ? "even" : "odd") ." number.
";
Ans:
if( $x%2 == 0)
echo "$x is an even number.
";
else
echo "$x is an odd number.
";