PHP Chapter 3
PHP Chapter 3
Variables:
They are memory locations for storing data values that can be changed or modified
during the execution of a program.
In PHP, a variable is declared with a $ symbol followed by the variable name, like
$varName.
Constants:
Constants store values that cannot be changed once they are defined.
In PHP, constants are defined using the define() function or by using the const
keyword and are case-sensitive by default.
Integer:
Boolean:
In strongly typed programming languages, data types are strictly enforced. You cannot
change the type of a variable once it’s declared, and type conversion must be explicit.
Loosely Typed:
In loosely typed languages (like PHP), variables are not bound to a specific type. PHP
automatically converts the variable type based on its value or context.
5. What is Concatenation?
This refers to joining two or more strings together using the concatenation operator . in
PHP
Practical Questions:
1. Write a simple program of the following output using Constants.
Employee code is 001
Employee Name is ABC
Employee Salary is 25000
Working Hours are 7.5
<?php
define("EMP_CODE", "001");
define("EMP_NAME", "ABC");
define("EMP_SALARY", 25000);
define("WORK_HOURS", 7.5);
<?php
echo GREETING;
?>
5. Write make a simple program to set your G.R No. and Name in the variables and
display G.R No. and name by echo and print functions.
<?php
$gr_no = "12345";
$name = "John Doe";
4. How many decimal places does an integer store Integer does not store decimal places.
a) One decimal
b) Two decimal
c) Three decimal
d) Integer does not store decimal places.