0% found this document useful (0 votes)
13 views4 pages

PHP Web App Development Practice Questions

Web Development

Uploaded by

aliyakubumuhd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

PHP Web App Development Practice Questions

Web Development

Uploaded by

aliyakubumuhd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

ITC3304 WEB APPLICATION DEVELOPMENT/PHP

PRACTICE QUESTIONS

PART 1: SYNTHAX

1. Write a PHP script to print a message 10 times.

2. Write a PHP script to print first 10 natural numbers.

3. Write a PHP script to find factorial of a number: a) Using for loop b) Using while loop

4. Write a PHP code snippet to print even nos. out of first 100 numbers

5. Describe what the ternary operator is in PHP and provide an example of how it's used for
conditional statements.

6. Write a PHP script to check whether the given number is even or odd (By using conditional
operator).

7. Write a PHP script to display days of week i.e. Monday to Sunday using switch-case statement.

8. Write a PHP code snippet to do following:

i. 1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

ii. 1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

iii.

1 2 1

1 2 3 2 1

1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
PART 2: FUNCTIONS

1. Write a PHP code snippet to calculate the sum of all prime numbers within a given range.

2. Write a PHP code snippet to calculate the length of a string without using the built-in strlen()
function

3. Write a PHP code snippet to input 2 no’s from the user & do their addition, subtraction,
multiplication & division.

4. Define a function called calculateSum that takes two parameters, $num1 and $num2, and
returns their sum. Use the function to calculate and echo the sum of 5 and 8.

5. Create a PHP function called calculatePower that takes two parameters, $base and
$exponent, and returns the result of raising the base to the power of the exponent. Use the
function to calculate and echo 2 raised to the power of 5.

6. Write a PHP function that takes a string as input and returns its reverse. Use this function to
reverse and display the string "Hello, world!"

7. Create a PHP function called calculate that takes two numbers and an operator (+, -, *, /) as
arguments and returns the result of the operation.

8. Develop a PHP function that converts temperature from Celsius to Fahrenheit. Use the formula:
Fahrenheit = (Celsius * 9/5) + 32.

9. Create a PHP function that generates an email address using a person's name and a domain.
Display the generated email.

10. Imagine you have a PHP script that calculates the total cost of items in a shopping cart. How
would you handle passing the item prices and quantities to the script and return the calculated
total?

11. Write a PHP function to calculate;


a. (a+b)2
b. (a+b)3
c. (a2-b2)
PART 3: ARRAYS

1. Write a PHP code snippet to convert a string to an array of characters

2. How do you create and use a multidimensional array in PHP? Provide two examples

3. Given an array of numbers, write PHP code to calculate and display the sum and average of

the numbers.

4. Given an array of numbers, write PHP code to find and display the maximum and minimum

values in the array.

5. Describe the purpose of the array_search(), array_key_exists(), array_merge() ,

array_reverse() array_shift() and array_pop() functions in PHP and provide an example of using

each.

6. Create a PHP function that calculates and displays the Body Mass Index (BMI) based on

weight and height inputs.

7. Suppose you have an array of student names and their corresponding scores. How could you

use a loop in PHP to calculate and display the highest and lowest scores along with the

corresponding student names?


PART 4: FORMS

1. Describe the difference between a POST request and a GET request in PHP, and how data is
transmitted in each.

2. How do you handle and process form data submitted via the POST method in PHP?

3. Describe the purpose of the header() function when used to set HTTP response headers in
PHP

4. Design a simple form that asks for a user's name and favorite color. When the form is
submitted, use PHP to display a message like "Hello [name], your favorite color is [color]."

5. Design a form that asks for a user's age. On submission, use the $_POST or $_GET
superglobal to retrieve the age and echo a message based on whether the user is a minor or an
adult.

6. Design a form that asks for a password. Write PHP code to validate whether the entered
password contains at least 8 characters and includes both letters and numbers. Provide appropriate
feedback based on the validation result.

7. Develop a number guessing game where the user tries to guess a random number between 1
and 100 generated by PHP. Provide hints like "Too high" or "Too low" until the correct number is
guessed.

8. Design a page that takes a user's name as a parameter in the URL (e.g.,
"example.com/?name=John"). Write PHP code to retrieve the name from the URL and display a
greeting like "Hello, John!"

9. Imagine you're working on a project where users can submit reviews for products. How could
you use PHP to validate and filter user-generated content to prevent inappropriate or malicious
submissions?

You might also like