0% found this document useful (0 votes)
16 views29 pages

Day 1 and 2

Uploaded by

ntanmayi13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views29 pages

Day 1 and 2

Uploaded by

ntanmayi13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

PHP

Prepared By,
Ms. Tanmayi Nagale
Introduction

• PHP is an acronym for "PHP: Hypertext Preprocessor"


• PHP is a widely-used, open source scripting language
• PHP scripts are executed on the server
• PHP is free to download and use
PHP Introduction
PHP Comments

•In PHP, we use // to make a


single-line comment or /* and */
to make a large comment block.
PHP Variables

•> 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

•> In PHP, a variable does not need to be declared before adding


a value to it.
•> In the example above, you see that you do not have to tell
PHP which data type the variable is.
•> PHP automatically converts the variable to the correct data
type, depending on its value.
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

• A string is a sequence of characters, like "Hello world!".


• A string can be any text inside quotes. You can use single or double quotes:
PHP var_dump() function

• $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

•The output of the code on the last slide will be:

•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

•Operators are used to operate on values. There are four classifications of


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

You might also like