Variables are used to store a value that can change during the program execution. PHP variables are part of Basic programming. Therefore, it is good to practice on these and understand basic PHP programming concepts.
Here, you will find Assignments & Exercises related to PHP Variables. These exercises list contains exercise description and instructions. You need to write a program as per instructions. Then you can match it with our solution.
All PHP exercises are available in the form of PHP program description, instruction and their solution. These PHP programs can also be given as an assignment for PHP students.
Write a program to print “Hello World” using echo only?
- You can not use any variable.
View Solution /Program
<?php echo "Hello World"; ?>
Write a program to print “Hello PHP” using php variable?
- You can not use text directly in echo but can use variable.
<?php $message = "Hello PHP"; echo $message; ?>
Write a program to print “Welcome to the PHP World” using some part of the text in variable & some part directly in echo.
- You have to use a variable that contains string “PHP World”.
<?php $message = "Welcome to the PHP World"; echo $message; ?>
Welcome to the PHP World
Write a program to print 2 php variables using single echo statement.
- First variable have text “Good Morning.”
- Second variable have text “Have a nice day!”
- Your output should be “Good morning. Have a nice day!”
- You are allowed to use only one echo statement in this program.
<?php $message_1 = "Good Morning."; $message_2 = "Have a nice day!"; echo $message_1." ". $message_2; ?>
Good Morning. Have a nice day!