10. PHP Data Types , Conditional & Iterative Statements
10. PHP Data Types , Conditional & Iterative Statements
pk
unioffaisalabad
Aasma Khalid
Lecturer
The University of Faisalabad
PHP DataTypes www.tuf.edu.pk
unioffaisalabad
• 1. String
• A string is a sequence of characters that holds letters and
numbers. It can be anything written inside single or double
quotes.
• For Example:
www.tuf.edu.pk
unioffaisalabad
2. Integer
An integer is a non-decimal number typically ranging
between -2,147,483,648 and 2,147,483,647.
3. Float
A float is a number with a decimal point. It can be an
exponential number or a fraction.
4. Boolean
A Boolean represents two values: True or False.
www.tuf.edu.pk
unioffaisalabad
5. Array
Array is a collection of similar data elements stored in a
single variable.
6. NULL
Null is a special data type with only one value which is
NULL. In PHP, if a variable is created without passing a
value, it will automatically assign itself a value of NULL.
PHP Operators www.tuf.edu.pk
unioffaisalabad
Iterative statements are used to run same block of code over and
over again for a certain number of times.
In PHP, we have the following loops:
– while Loop
– do-while Loop
– for Loop
– foreach loop
While Loop www.tuf.edu.pk
unioffaisalabad
The foreach loop in PHP can be used to access the array indexes
in PHP. It only works on arrays and objects.
Function Basics www.tuf.edu.pk
unioffaisalabad
Function arguments are variables of some supported data type that are processed
within the body of the function. It can take input as an argument and return value.
PHP has more than 1000 built-in functions, and in addition, you can also create
your own functions.
Advantages:
• Functions reduce the complexity of a program and give it a modular structure.
• A function can be defined only once and called many times.
• It saves a lot of code writing because you don't need to write the same logic
multiple times, you can write the logic once and reuse it.
www.tuf.edu.pk
unioffaisalabad
Any question?