Q:

PHP find output programs (basics) | set 1

belongs to collection: PHP Find Output Programs

0

Find the output of PHP programs | Basics | Set 1: Enhance the knowledge of PHP basic concepts by solving and finding the output of some PHP basic programs.

Question 1:

<?php
    int $x = 15;
    int $y = 20;
    int $z = 0;
    
    $z = $x + $y * 2;
    
    echo $z;
?>

Question 2:

<?php
    $PI = 3.14F;
    $RAD = 5;
    
    $AREA = $PI * $RAD * $RAD;
    echo $AREA;
?>

Question 3:

<?php
    $PI = 3.14;
    $RAD = 5;
    
    $AREA = $PI * $RAD * $RAD;
    echo $area;
?>

Question 4:

<?php
    $PI = 3.14;
    $RAD = 5;
    
    $AREA = $PI * $RAD * $RAD;
    echo "Area of circle: " + $AREA;
?>

Question 5:

<?php
    $A = 3.14;
    $B = 5;
    $C = "Hello"
    
    echo var_dump($A);
    echo var_dump($B);
    echo var_dump($C);
?>

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer 1:

Output:

PHP Parse error:  syntax error, unexpected '$x' (T_VARIABLE) 
in /home/main.php on line 2

Explanation:

The above program will generate syntax error because we cannot use explicit data types like int, float, char in PHP. In PHP, the data-type of a variable depends on data stored in it. If we store integer number then the variable becomes integer type or if we store floating-point number then it becomes float type.

Answer 2:

Output:

PHP Parse error:  syntax error, unexpected 'F' (T_STRING) 
in /home/main.php on line 2

Explanation:

The above program will generate syntax error because we used 'F' in the suffix of $PI value, which is not allowed in PHP.

Answer 3:

Output:

PHP Notice:  Undefined variable: area in /home/main.php on line 6

Explanation:

The above program will generate error notice because variables are case sensitive in PHP, we used $area instead of $AREA in the echo statement.

Answer 4:

Output:

78.5

Explanation:

In the above program, we declared two $PI and $RAD initialized with 3.14 and 5 respectively. Now we evaluate the below expression:

$AREA= $PI * $RAD * $RAD;
$AREA=3.14*5*5;
$AREA=15.70*5;
$AREA=78.5;

Then we used '+' operator in the echo statement for string concatenation. But '+' operator is not used for concatenation, here we need to use '.' Operator for concatenation like below statement.

echo "Area of circle: ".$AREA;

So that echo statement will print the only value of $AREA, instead of a complete string.

Answer 5:

Output:

PHP Parse error:  syntax error, unexpected 'echo' (T_ECHO) 
in /home/main.php on line 6

Explanation:

The above program will generate syntax error because we semicolon ';' is missing in the below statement.

$C  = "Hello"

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP Find Output Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
PHP find output programs (basics) | set 2... >>