MIS 423 Web Application Development Assignment #2


Subject: MIS 423- Web Application Development 

Instructor: Dr. Walaa Abdelfattah


Question 1




The reason why "WELCOME" is the output as a result of this code's execution is because it meets the set condition of the if statement. Simply the condition is an arithmetic operation of the values of $x1, $x2, and $x3. Since this operation returns true, the code will execute the statement "echo "WELLCOME" which gives the above output.

Question 2




The print statement returns 1, but since the if (!print "Hello") statement uses the! It will return a 0 instead. Therefore only (!print "Hello") will be executed, and the rest will not be executed.

Question 3


PHP Parse error:  syntax error, unexpected ')' on line 2


The error output is expected since one can easily observe a while loop is used without a condition. Therefore, this will result in an error on the line with the while loop until a set condition is given.

Question 4


I'm Do While loop

Hello I'm Question 04


First, the output is in different lines since a <br> is used. Further, this code first executes a do…while loop, which executes the "print "I'm Do While loop <br>" statement giving us the first output. Then the second output is printed automatically since "print " Hello I'm Question 04" is outside the do…while loop and does not have a set condition to execute.

Question 5


The number is 0

The number is 1

The number is 2


First, we need to understand that this is a do…while loop code. Therefore, this code loops through the block of code given once and then loops again as long as the set condition remains true. In the given code textx is declared and assigned the value 0, which after execution increases the value of $textx by 1. This loop is repeated by executing the statement "echo "The number is " . $testx. "<br>"” until the condition $testx != 3 is met thus giving as the three outputs above.

Question 6


I started the loop

I finalized the loop


This loop code executes only once as the value of i is incremented, thus executing both statements print "I started the loop <br>" and "print "I finalized the loop\n"

Question 7




The condition "$colors[$x] == "Ball" is true when $colors[$x] is equal to 1 which holds the element “ball”. Therefore, this iteration breaks since the condition is true, and the loop continues until $x is found to be greater than 3. As a result, only ‘RedGreenYellow’ will be printed, and ‘ball’ will be skipped.

Question 8


I love arsenalI love manc


This PHP case code is supposed to output when the case "arsenal" is found but also executes the statements after "arsenal is found. This is because if a break statement is not found, all the following case blocks execute by default until a break statement is found.


Question 9


PHP Parse error:  syntax error, unexpected '$x' (T_VARIABLE) on line 9


The "PHP Parse error:  syntax error, unexpected '$x' (T_VARIABLE)" on a PHP code is mostly associated with syntax errors like failure to follow the PHP syntax like the use of brackets and semicolons as in the case of this code.

Question 10


how are u


In this code, $x is declared with no value assigned; therefore, the if statement returns false hence printing what's in the else statement.

Question 11




This code is in two parts, where the first part is a do…while loop. Therefore, this code should execute the "print "hi" statement just once since the condition set is while (0). Then the other part is located outside the do…while loop hence automatically executing to give the output of hello. However, these two outputs will appear in one line because there is no <br> statement to separate them.


Trace the output of the following code:

Question 1


Array ( [zero] => 2000 [one] => 3000 [two] => 500 )


Step #1

$numbers = array("1000","2000","300","400", "5000");

‘numbers’ is declared as an array and assigned 5 values

Step #2

foreach ($numbers as $value)

$value is assigned the array $numbers

Step #3

echo "$value <br>";

$value is printed and moves to the next line

Step #4

$numbers = array("zero" => 2000, "one" => 1000, "two" => 500, "one" => 2000, "one" => 3000)

Declaration of $numbers as an associative array

Step #5


The contents of variable $numbers are printed


Question 2

Output: Error

Step #1

for ($count = 0; $count<3;$count++);

Count is set to 0, and it is checked if it's below 3.

Step #2

print "hi";break;print "hello";

“hi” and “hello” is to be printed, but an error occurs since “break” is used here, and PHP does not allow the use of ‘break’ in this code. The loop should iterate until when count is above 3 or else terminate. However, in this case, the code cannot execute because of the case “statement.”


Question 3

Output: PHP Parse error:  syntax error, unexpected 'else' (T_ELSE) on line 10

Step 1

$myarray = array("Cycle" => 2, "Bike" => 5, "Car" => 9);

Associative array $myarray is declared and assigned values and its keys

Step 2


$arrsize = count($myarray);

The number of elements of the array $myarray is obtained and assigned to the variable $arrsize

Step 3


$keys = array_keys($myarray);

returns the keys from the array $myarray and assigned to the variable $keys

Step 4



$myarray is sorted here using Ksort statement to sort it in in a descending order in reference to the keys

Step 5


for ($x = 0; $x < $arrsize; $x++)

$x is set to 0, and it is checked if it's below $arrsize

Step 6


if($myarray[$keys[$x]] > 2)

If statements checks whether $myarray[$keys[$x]] is above 2

Step 7


echo "Type is: ".$keys[$x].", "."NUM is: ".$myarray[$keys[$x]];

If it returns true, the key and array element output are printed.

Step 8


echo "<br>";

This command instructs the code to move to the next line of the output screen, but an error occurs because this statement should be in between brackets

Step 9



If the condition had returned a false, the else statement is to be executed

Step 10


echo "Type is: ".$keys[$x].", "."NUM is: ".$myarray[$keys[$x]];

A print statement is executed if the condition is false, which also outputs of the key and array element are printed. Also, an error occurs here because this statement should be in between brackets


All Answers

total answers (0)

Similar questions

need a help?

find thousands of online teachers now