$length = 50;
$width = 5;
$area = $length * $width;
echo "The area of the Rectangle is $area"
The area of the Rectangle is 250
$amount = 150; $conversion_rate = 0.99; $converted_amount = $amount * $conversion_rate; echo "A P$amount is $$converted_amount in US Dollars"
A P150 is $2.7 in US Dollars
$total_donation = 300; $new_donation = 30; $total_donation += $new_donation; echo "The fundraising campaign has $total_donation donations";
The fundraising campaign has 330 donations
$candidate1_votes = 91;
$candidate2_votes = 110;
$user_vote = 1;
$user2_vote = 2;
$candidate1_votes += $user_vote;
$candidate2_votes += $user2_vote;
echo "Candidate 1 votes: $candidate1_votes\n
Canditate 2 votes: $candidate2_votes\n
Canditate 2 wins!";
Candidate 1 votes: 92
Canditate 2 votes: 112
Canditate 2 wins!
$athlete1= 10.51;
$athlete2 = 9.11;
$winner;
if($racer1 < $racer2){
$winner = "Athlete 1";
}else{
$winner = "Athlete 2";
}
echo "$winner wins in $athlete2 seconds";
Athlete 2 wins in 9.11 seconds
$algorithm1= 3;
$algorithm2 = 5;
$winner;
if($algorithm1 < $algorithm2){
$winner = "Algorithm 1";
} else{
$winner = "Algorithm 2";
}
echo "$winner is the faster algorithm\n
Time: $algorithm1 n";
Algorithm 1 is the faster algorithm
Time: 3 n
$nNumber = 5;
$factorial = 1;
for($i = 1;$i <= $nNumber; $i++){
$factorial *= $i;
}
echo "The factorial of $nNumber is $factorial";
The factorial of 5 is 120
$position = 0; $distance = 10; $forward = $position += ++$distance; echo "Previous Position: $previous
Final Position: $forward";
Previous Position: 10
Final Position: 11
$purchaseAmount = 100; $loyaltyMember = true; $discountReal = ($purchaseAmount >= 100 && $loyaltyMember == true) ? "Yes, I am eligible for discount" : "No, I'm not eligible for discount"; echo "Are you eligible for discount? $discountReal";
Are you eligible for discount? Yes, I am eligible for discount
$userQuery = "location"; $response = ($userQuery == "location") ?"We are in the Philippines": "I don't know that."; echo "User Query: $userQuery\nChatbot Response: $response ";
User Query: location
Chatbot Response: We are in the Philippines