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);
?>
Answer 1:
Output:
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:
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:
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:
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:
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