PHP Find Output Programs
- PHP find output programs (basics) | set 1
- PHP find output programs (basics) | set 2
- PHP find output programs (basics) | set 3
- PHP find output programs (Superglobals) | set 1
- PHP find output programs (conditional statements) | set 1
- PHP find output programs (conditional statements) | set 2
- PHP find output programs (conditional statements) | set 3
- PHP find output programs (switch Statement) | set 1
- PHP find output programs (switch Statement) | set 2
- PHP find output programs (switch Statement) | set 3
- PHP find output programs (Operators) | set 1
- PHP find output programs (Operators) | set 2
- PHP find output programs (Operators) | set 3
- PHP find output programs (Loops) | set 1
- PHP find output programs (Loops) | set 2
- PHP find output programs (Loops) | set 3
- PHP find output programs (Loops) | set 4
- PHP find output programs (Arrays) | set 1
- PHP find output programs (Arrays) | set 2
- PHP find output programs (Arrays) | set 3
- PHP find output programs (User-defined functions) | set 1
- PHP find output programs (User-defined functions) | set 2
- PHP find output programs (User-defined functions) | set 3
- PHP find output programs (String Functions) | set 1
- PHP find output programs (String Functions) | set 2
- PHP find output programs (Number Functions) | set 1
- PHP find output programs (Math Functions) | set 1
- PHP find output programs (Math Functions) | set 2
- PHP find output programs (Date and Time) | set 1
- PHP find output programs (define Constant) | set 1
- PHP find output programs (static variables, classes, methods) | set 1
- PHP find output programs (static variables, classes, methods) | set 2
- PHP find output programs (Regular Expressions) | set 1
- PHP find output programs (Exceptions) | set 1
- PHP find output programs (Exceptions) | set 2
- PHP find output programs (Filters) | set 1
- PHP find output programs (Filters) | set 2
- PHP find output programs (JSON) | set 1
- PHP find output programs (const Keyword) | set 1
- PHP find output programs (Class & Objects) | set 1
- PHP find output programs (Class & Objects) | set 2
- PHP find output programs (Class & Objects) | set 3
- PHP find output programs (Constructors and Destructors) | set 1
- PHP find output programs (Constructors and Destructors) | set 2
- PHP find output programs (Constructors and Destructors) | set 3
- PHP find output programs (Inheritance) | set 1
- PHP find output programs (Inheritance) | set 2
- PHP find output programs (Inheritance) | set 3
Answer 1:
Output:
Explanation:
In the above program, we created two variables $x and $NUM initialized with 1 and 5 respectively. Here, we used while loop, in the condition of while loop, strlen() function is used.
The strlen() returns the length of the specified string. the strlen("ABCDEFGHIJ") will return 10. So that condition of while loop will be true until the value of $x is less than or equal to 10.
The value of $x increase from 1 to 10, when it becomes 11 then the loop will terminate. We used the printf() function inside the body of the loop to print values in each iteration and the value of $x will increase in each iteration.
Answer 2:
Output:
Explanation:
In the above program, we created $RES with initial value 1 and created one more variable $NUM, which is initialized with the value returned by printf() function. The printf() function will return the total number of characters printed on the webpage.
Here, $NUM will be initialized with 5.
Here, loop condition will true until $num becomes 0. In the body of the loop value of the $NUM will decrease in each iteration.
$NUM=5, $RES=1 $RES = 1 * 5; $RES = 5; Then $NUM will be 4 after decrement. $NUM=4, $RES=5 $RES = 5 * 4; $RES = 20; Then $NUM will be 3 after decrement. $NUM=3, $RES=20 $RES = 20 * 3; $RES = 60; Then $NUM will be 2 after decrement. $NUM=2, $RES=60 $RES = 60 * 2; $RES = 120; Then $NUM will be 1 after decrement. $NUM=1, $RES=60 $RES = 120 * 1; $RES = 120;
Then $NUM will be 0 after decrement. And loop condition will false and print 120 on the webpage.
Answer 3:
Output:
Explanation:
In the above program, we created $RES with initial value 1 and created one more variable $NUM, which is initialized below expression.
Th pow() function will return 4 and print() function will return 1. Because print() function will return 1 on successful printing of data.
Here, $NUM will be initialized with 5.
Here, loop condition will true until $num becomes 0. In the body of the loop value of $NUM will decrease in each iteration.
$NUM=5, $RES=1 $RES = 1 * 5; $RES = 5; Then $NUM will be 4 after decrement. $NUM=4, $RES=5 $RES = 5 * 4; $RES = 20; Then $NUM will be 3 after decrement. $NUM=3, $RES=20 $RES = 20 * 3; $RES = 60; Then $NUM will be 2 after decrement. $NUM=2, $RES=60 $RES = 60 * 2; $RES = 120; Then $NUM will be 1 after decrement. $NUM=1, $RES=60 $RES = 120 * 1; $RES = 120;
Then $NUM will be 0 after decrement. And loop condition will false and print 120 on the webpage.
Answer 4:
Output:
Explanation:
The above program will generate a compilation error because of the below statement.
$NUM = (1,2,3,4,5);
We cannot initialize values to $NUM like this.
Answer 5:
Output:
Explanation:
The above program will print "16" on the webpage. In the above program, we created $RES initialized with 1. Here, we used counter variable $I, which is initialized with 1 and loop condition will true until it becomes more than 5.
$I=1, $RES=1 condition will true $RES = $RES + $I; $RES = 1 + 1; $RES = 2; $I=2, $RES=2 condition will true $RES = $RES + $I; $RES = 2 + 2; $RES = 4; $I=3, $RES=4 condition will true $RES = $RES + $I; $RES = 4 + 3; $RES = 7; $I=4, $RES=7 condition will true $RES = $RES + $I; $RES = 7 + 4; $RES = 11; $I=5, $RES=11 condition will true $RES = $RES + $I; $RES = 11 + 5; $RES = 16;
$I=6, $RES=16 condition will false and 16 will print on the webpage.
need an explanation for this answer? contact us directly to get an explanation for this answer