Day 1 and 2
Day 1 and 2
Prepared By,
Ms. Tanmayi Nagale
Introduction
•> Variables are used for storing values, like text strings,
numbers or arrays.
•> When a variable is declared, it can be used over and over
again in your script.
•> All variables in PHP start with a $ sign symbol.
•> The correct way of declaring a variable in PHP:
PHP Variables
•> A variable name must start with a letter or an underscore "_" -- not a
number
•> A variable name can only contain alpha-numeric characters,
underscores (a-z, A-Z, 0-9, and _ )
•> A variable name should not contain spaces. If a variable name is more
than one word, it should be separated with an underscore ($my_string) or
with capitalization ($myString)
PHP ECHO/PRINT
• The echo statement can be used with or without parentheses: echo or echo().
• echo and print are more or less the same. They are both used to output data to
the screen.
• The differences are small: echo has no return value while print has a return
value of 1 so it can be used in expressions.
• echo can take multiple parameters (although such usage is rare) while print
can take one argument. echo is marginally faster than print.
Display Variables
Output:
PHP Print Statement
• The print statement can be used with or without parentheses: print or
print().
Display Variables
PHP Data Types
• Variables can store data of different types, and different data types can do different things.
• PHP supports the following data types:
• String
• Integer
• Float (floating point numbers - also called double)
• Boolean
• Array
• Object
• NULL
• Resource
PHP String
• $x is an integer. The PHP var_dump() function returns the data type and
value
PHP min() and max() Functions
PHP Constants
• A constant is an identifier (name) for a simple value. The value cannot be
changed during the script.
• A valid constant name starts with a letter or underscore (no $ sign before
the constant name).
PHP Constants
PHP Concatenation
•> The concatenation operator (.) is used to put two string values together.
•> To concatenate two string variables together, use the concatenation operator:
PHP Concatenation
•If we look at the code you see that we used the concatenation operator two
times. This is because we had to insert a third string (a space character), to
separate the two strings.
PHP Operators
• > Arithmetic
• > Assignment
• > Comparison
• > Logical
PHP Arithmetic Operators
PHP Assignment Operators
PHP Assignment Operators
PHP Comparison Operators
PHP Increment / Decrement Operators
PHP Logical Operators
PHP String Operators
PHP Array Operators
PHP Conditional Assignment Operators