PHP Variables
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
Description:
Write a program to print “Hello World” using echo only?
Conditions:
- You can not use any variable.
View Solution /Program
<?php
echo "Hello World";
?>
Hello World
Write a program to print “Hello PHP” using variable
Description:
Write a program to print “Hello PHP” using php variable?
Conditions:
- You can not use text directly in echo but can use variable.
View Solution/Program
<?php
$message = "Hello PHP";
echo $message;
?>
Hello PHP
Write a program to print a string using echo+variable.
Description:
Write a program to print “Welcome to the PHP World” using some part of the text in variable & some part directly in echo.
Conditions:
- You have to use a variable that contains string “PHP World”.
View Solution/Program
<?php
$message = "Welcome to the PHP World";
echo $message;
?>
Welcome to the PHP World
Write a program to print two variables in single echo
Description:
Write a program to print 2 php variables using single echo statement.
Conditions:
- 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.
View Solution/Program
<?php
$message_1 = "Good Morning.";
$message_2 = "Have a nice day!";
echo $message_1." ". $message_2;
?>
Good Morning. Have a nice day!