PHP Exercises

Today we will see some of PHP exercises which will help you in understanding PHP course more. If you don’t get right the question we have also provided solution for each question. This questions may include;

1. Write your first program in php, print “hello world, i am learning php”. (See Solution Here)

2. Define two variables(name,age) and print out in form of a statement telling us your name and age. (See Solution Here)

3. Create two variables(x,y) add them ad multiply answer by 6. Print your answer as a variable ‘z’. (See Solution Here)

4. Create an array that shows capital cities of any 3 countries. (See Solution Here)

5. Create two variables(price,vat). Create a new variable ‘totalPrice’ then calculate the vat on the price and print out the(vat,price,total Price). (See Solution Here)

6. Create three variables(x,y,z) and then calculate the average of the three numbers. Make sure the output has a decimal point, therefore you have to round to 2 decimal places. (See Solution Here)

7. Create a function(evenOrNot) that can be used to check whether a given number(num1) is even number or odd number, then you print out(number is even or number is odd). (See Solution Here)

8. Create a variable(year) and then create a fucntion(isLeapYear) that can be used to check whether a certain year is a leap year. If it is a leap year then returns a Boolean value. (See Solution Here)

9. Create two variables(price,vat) and then create a function(calculateVat) that takes the two parameters and then returns the variables(calculatePrice). You will have to echo(price,vatm,total price). (See Solution Here)

10. Create a function(swapNumbers) that takes the two paramaters(num1,num2) and inside the function,that swaps the numbers(num1,num2). (See Solution Here)

You may be interested to learn the PHP Full course, start now;PHP COURSE. Thanks for choosing learntechphilloh program.