Write a PHP script to calculate the area of a rectangle using arithmetic operators. Display the result. (area of a rectangle: $area = $length * $width; )
$length = 5; $width = 9; $area = $length * $width; echo "A rectangle with length $length and width $width has an area of $area";
Implement a script that converts currency from one denomination to another using arithmetic operators. Display the converted amount. (Convert currency: $converted_amount = $amount * $conversion_rate;)
$php = 100; $conversionRate = 0.028; $converted = $php * $conversionRate; echo "$php PHP is equivalent to $converted AUD";
Track the progress of a fundraising campaign by updating the donation total dynamically using combined assignment operators. Display the updated total. . (Track fundraising: $total_donation += $new_donation;)
$total = 0; $new = 69; $total += $new; echo "Total Donation: $total";
Implement a voting system where candidate votes are incremented based on user input. Display the final vote count for each candidate. (Voting system: $candidate_votes += $user_vote;)
$c1Votes = 34; $c2Votes = 25; $p1 = $p2 = $p3 = $p4 = 1; $c1Votes += $p1 + $p2 + $p4; $c2Votes += $p3; echo " Candidate 1 Votes: $c1Votes Candidate 2 Votes: $c2Votes ";
Compare the performance of two athletes in a race and determine the winner using comparison operators. Display the result. (Compare athlete times: Use '<' to compare times.)
$athlete1_t = 12; $athlete2_t = 11; $winner = ($athlete1_t < $athlete2_t) ? "Athlete 1" : "Athlete 2"; echo $winner . " is the winner";
Evaluate the efficiency of two algorithms based on their execution times using comparison operators. Display the more efficient algorithm. (Evaluate algorithm efficiency: Use '<' to compare times.)
$alg1 = 1.31; $alg2 = 1.55; $faster = ($alg1 < $alg2) ? "Algorithm 1" : "Algorithm 2"; echo "The faster algorithm is $faster";
Calculate the factorial of a number using postfix increment/decrement operations. Display the factorial. (Calculate factorial: Use a loop to multiply numbers.)
$number = 5;
$factorial = 1;
for($i = 1; $i <= $number; $i++){
$factorial *= $i;
}
echo "$number! = $factorial";
Simulate the movement of a vehicle along a track using prefix increment/decrement operations. Display the final position of the vehicle. (Simulate vehicle movement: Use += for forward movement.)
$startPos = 0; $travel = 99; $startPos += $travel; echo "Vehicle at final position $startPos";
Determine eligibility for a discount based on purchase amount and customer loyalty using logical operators. Display whether the customer is eligible for a discount. (Determine discount eligibility: Use && to check conditions.)
$amount = 301; $loyalCustomer = true; $eligible = ($amount > 300 && $loyalCustomer) ? "Eligible" : "Not eligible"; echo $eligible . " for discount";
Design a decision-making system for a chatbot to respond to user queries using logical operators. Display the appropriate response based on the query. (Chatbot decision-making: Use ? : for simple conditions.)
$userQuery = "moon phase"; $botResponse = ($userQuery == "moon phase") ? "Tonight is a full moon" : "I don't understand your question"; echo "ChatBot Response: $botResponse"