SlideShare a Scribd company logo
1 of 39
Introduction to PHP
Outline
• Why PHP?
• Info Sources
• A Walk Through PHP
• Variables
• Data Types
• Type Casting
• Constants
• Operators
• Control Structures
• Assignment
• What's Next?
Why PHP?
• Server-side scripting ( web development )
from basic to fully enterprise. ( the majority
of facebook code is in PHP ).
• Command-Line scripting.
• Client-side GUI applications (using PHP GTK).
• Supported on all Operating systems.
• Can be embedded into HTML.
• Easy to learn.
Why PHP?
• Around 21M websites are using PHP until 2007
Info Sources
• http://www.php.net/
• http://www.mysql.com/
A Walk Through PHP
• Opening/ closing tags :
– <?php ?> (preferred)
– <? ?>
– <% %>
– <script language="php"> </script>
• Statements end with semi-colon ‘;’ :
$x = 10;
A Walk Through PHP
• White spaces and Line breaks do not matter.
• Comments :
– # Single-line comments (or when a code block ends ‘?>’)
– // Single-line comments (or when a code block ends ‘?>’)
– /*
Multi-line comments
*/ (can’t be nested)
Variables
• Start with a dollar sign ‘$’.
• Can contain upper/ lower case letters,
number and underscores.
• Can’t start with a number (after the ‘$’ sign).
• They are case sensitive.
Variables
• Examples:
– Legal:
• $name
• $_name
• $name_12
– Illegal:
• $not valid
• $12name
• $|
– These identifiers are not the same: ( $hi, $Hi ).
Data Types
PHP is weakly typed language.
1.Integer:
– Example :
• $x = 12000
• $y = +50
• $z = -30
Data Types
1. Floating Point:
– Examples:
• $x = 0.45
• $y = +20.2
• $z = -40.11
• $k = +0.345E2
• $d = -0.234E-3
Data Types
1. String:
– Sequence of characters with an arbitrary length.
– Examples:
• $name = ‘Mohamed’;
• $name = “Mohamed”;
• $str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;
• echo ‘here is it’;
• print “line 1 n line2”;
• $name = ‘john’; echo “Hello $name”;
Data Types
1. Boolean:
– true or false values.
– Used in conditional statements.
– Example :
$value = true;
If( $value == true )
// do something
Data Types
1. Array:
– A collection that holds a number of values.
– Example:
$x = array(“Hi”, “Hello”, 3, 4.01 ).
Data Types
1. Objects:
– A class is a definition of some variables and
functions that maps to a real entity.
– Example :
class Person{
private $var=‘’;
public function getVar(){
return $var;
}
}
Data Types
1. Resource:
– It is an identifier for an external connection or
object (database or file handle).
Data Types
1. NULL:
– It is the no-value value.
– Example:
$x = 10;
$x = NULL; //value is gone
Type Casting
<?php
$foo = (float)'1'; // 1.0
$foo = (int)10.5; // 10
$foo = (boolean) 5; // true
?>
Type Casting
<?php
$foo = "0"; // $foo is string
$foo += 2; // $foo is now an integer (2)
$foo = $foo + 1.3; // $foo is now a float (3.3)
$foo = 5 + "10 Little Piggies"; // $foo is integer (15)
$foo = 5 + "10 Small Pigs"; // $foo is integer (15)
?>
Constants
– Is an identifier (name) for a simple value. that
value cannot change during the execution of the
script.
– Example:
• define("FOO", "something"); // valid
• define("2FOO", "something"); // not valid
Operators
– An operator is a symbol that takes arguments
and returns a value.
– Arithmetic Operators :
Operator Description Example Result
+ Addition x=2
x+2
4
- Subtraction x=2
5-x
3
* Multiplication x=4
x*5
20
/ Division 15/5
5/2
3
2.5
%
Modulus (division
remainder)
5%2
10%8
10%2
1
2
0
++ Increment x=5
x++
x=6
-- Decrement x=5
x--
x=4
Operators
• Assignment Operators:
Operator Example Is The Same As
= x=y x=y
+= x+=y x=x+y
-= x-=y x=x-y
*= x*=y x=x*y
/= x/=y x=x/y
.= x.=y x=x.y
%= x%=y x=x%y
Operators
• Comparison Operators:
Operator Description Example
== is equal to 5==8 returns false
!= is not equal 5!=8 returns true
<> is not equal 5<>8 returns true
> is greater than 5>8 returns false
< is less than 5<8 returns true
>= is greater than or equal to 5>=8 returns false
<= is less than or equal to 5<=8 returns true
=== Identical to 5 === “5” returns false
Operators
• Logical Operators :
Operator Description Example
&& And x=6
y=3
(x < 10 && y > 1) returns true
|| Or x=6
y=3
(x==5 || y==5) returns false
! not x=6
y=3
!(x==y) returns true
Advanced trick
• Variable variables :
$x = "name";
$name = 10;
echo $$x; // 10
Control Structures
• ‘If’ statement :
<?php
if ($a > $b)
echo "a is bigger than b";
?>
• ‘else’ statement :
<?php
if ($a > $b) {
echo "a is greater than b";
} else {
echo "a is NOT greater than b";
}
?>
Control Structures
• ‘elseif’ / ‘else if’ :
<?php
if ($a > $b) {
echo "a is bigger than b";
} elseif ($a == $b) {
echo "a is equal to b";
} else {
echo "a is smaller than b";
}
?>
Demo
Control Structures
• ‘switch’ statement:
– The switch statement is similar to a series of
IF/else statements on the same expression.
if ($i == 0) {
echo "i equals 0";
} elseif ($i == 1) {
echo "i equals 1";
} else {
echo “i equals another value”;
}
switch ($i) {
case 0:
echo "i equals 0";
break;
case 1:
echo "i equals 1";
break;
default:
echo “i equals another value”;
}
=
Control Structures
• Loops:
– ‘for’
– ‘while’
– ‘do while’
– ‘foreach’ (will be discussed more in Arrays)
Control Structures
• The ‘for’ loop:
for( $i = 0; $i <= 5; $i++ )
{
echo $i . " ";
}
Control Structures
• The ‘while’ loop:
$i = 0;
While( $i < 5 ){
echo $i;
$i++;
}
Control Structures
• The ‘do while’ loop:
$i = 0;
do {
echo $i;
$i++;
} while ($i < 5);
Demo
Control Structures
• ‘break’ keyword :
– break ends execution of the current for, foreach,
while, do-while or switch structure.
– Example:
While( $x ){
If( $y )
break;
echo $x;
}
Control Structures
• ‘continue’ keyword :
– continue is used within looping structures to skip the rest
of the current loop iteration and continue execution at
the condition evaluation and then the beginning of the
next iteration.
– Example:
While( $x < 5 ){
If( $x == 2 ){
$x++;
continue;
}
echo $x;
$x++;
}
Assignment
• Write a PHP snippet that will generate the following
output :
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
What's Next?
• Functions.
Questions?

More Related Content

What's hot

07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboardsDenis Ristic
 
php 2 Function creating, calling, PHP built-in function
php 2 Function creating, calling,PHP built-in functionphp 2 Function creating, calling,PHP built-in function
php 2 Function creating, calling, PHP built-in functiontumetr1
 
PHP Unit 3 functions_in_php_2
PHP Unit 3 functions_in_php_2PHP Unit 3 functions_in_php_2
PHP Unit 3 functions_in_php_2Kumar
 
Php Chapter 2 3 Training
Php Chapter 2 3 TrainingPhp Chapter 2 3 Training
Php Chapter 2 3 TrainingChris Chubb
 
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop NotesPamela Fox
 
Object-Oriented Programming with PHP (part 1)
Object-Oriented Programming with PHP (part 1)Object-Oriented Programming with PHP (part 1)
Object-Oriented Programming with PHP (part 1)Bozhidar Boshnakov
 
Arrays &amp; functions in php
Arrays &amp; functions in phpArrays &amp; functions in php
Arrays &amp; functions in phpAshish Chamoli
 
Dev traning 2016 basics of PHP
Dev traning 2016   basics of PHPDev traning 2016   basics of PHP
Dev traning 2016 basics of PHPSacheen Dhanjie
 

What's hot (20)

07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
 
php 2 Function creating, calling, PHP built-in function
php 2 Function creating, calling,PHP built-in functionphp 2 Function creating, calling,PHP built-in function
php 2 Function creating, calling, PHP built-in function
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Introduction in php part 2
Introduction in php part 2Introduction in php part 2
Introduction in php part 2
 
PHP Unit 3 functions_in_php_2
PHP Unit 3 functions_in_php_2PHP Unit 3 functions_in_php_2
PHP Unit 3 functions_in_php_2
 
Php Chapter 2 3 Training
Php Chapter 2 3 TrainingPhp Chapter 2 3 Training
Php Chapter 2 3 Training
 
PHP - Introduction to PHP
PHP -  Introduction to PHPPHP -  Introduction to PHP
PHP - Introduction to PHP
 
PHP Basic
PHP BasicPHP Basic
PHP Basic
 
Sorting arrays in PHP
Sorting arrays in PHPSorting arrays in PHP
Sorting arrays in PHP
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
Intermediate PHP
Intermediate PHPIntermediate PHP
Intermediate PHP
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
 
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop Notes
 
Php variables (english)
Php variables (english)Php variables (english)
Php variables (english)
 
Object-Oriented Programming with PHP (part 1)
Object-Oriented Programming with PHP (part 1)Object-Oriented Programming with PHP (part 1)
Object-Oriented Programming with PHP (part 1)
 
Basic PHP
Basic PHPBasic PHP
Basic PHP
 
Arrays &amp; functions in php
Arrays &amp; functions in phpArrays &amp; functions in php
Arrays &amp; functions in php
 
Dev traning 2016 basics of PHP
Dev traning 2016   basics of PHPDev traning 2016   basics of PHP
Dev traning 2016 basics of PHP
 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
 
php basics
php basicsphp basics
php basics
 

Viewers also liked

Class 1 - World Wide Web Introduction
Class 1 - World Wide Web IntroductionClass 1 - World Wide Web Introduction
Class 1 - World Wide Web IntroductionAhmed Swilam
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingAhmed Swilam
 
Class 4 - PHP Arrays
Class 4 - PHP ArraysClass 4 - PHP Arrays
Class 4 - PHP ArraysAhmed Swilam
 
Class 6 - PHP Web Programming
Class 6 - PHP Web ProgrammingClass 6 - PHP Web Programming
Class 6 - PHP Web ProgrammingAhmed Swilam
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP StringsAhmed Swilam
 
Data types in php
Data types in phpData types in php
Data types in phpilakkiya
 
Introduction to Web Programming: PHP vs ASP.NET
Introduction to Web Programming: PHP vs ASP.NETIntroduction to Web Programming: PHP vs ASP.NET
Introduction to Web Programming: PHP vs ASP.NETMorteza Zakeri
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJSAnass90
 
Trends and innovations in web development course
Trends and innovations in web development course Trends and innovations in web development course
Trends and innovations in web development course Dr. Shikha Mehta
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScriptAnass90
 
League of extraordinary front end dev tools
League of extraordinary front end dev toolsLeague of extraordinary front end dev tools
League of extraordinary front end dev toolsSherif Tariq
 
Front-end Web Dev (HK) Info Session
Front-end Web Dev (HK) Info SessionFront-end Web Dev (HK) Info Session
Front-end Web Dev (HK) Info SessionAllison Baum
 
Complete Web Development Course - Make Cash Earning Websites
Complete Web Development Course - Make Cash Earning WebsitesComplete Web Development Course - Make Cash Earning Websites
Complete Web Development Course - Make Cash Earning Websitesbuenosdias1989
 
Introduction to Front End Engineering
Introduction to Front End EngineeringIntroduction to Front End Engineering
Introduction to Front End EngineeringMark Meeker
 
Front-end Engineering Concepts
Front-end Engineering ConceptsFront-end Engineering Concepts
Front-end Engineering ConceptsSameer Karve
 
PHP MVC Tutorial 2
PHP MVC Tutorial 2PHP MVC Tutorial 2
PHP MVC Tutorial 2Yang Bruce
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Phpfunkatron
 

Viewers also liked (20)

Class 1 - World Wide Web Introduction
Class 1 - World Wide Web IntroductionClass 1 - World Wide Web Introduction
Class 1 - World Wide Web Introduction
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
Class 4 - PHP Arrays
Class 4 - PHP ArraysClass 4 - PHP Arrays
Class 4 - PHP Arrays
 
Class 6 - PHP Web Programming
Class 6 - PHP Web ProgrammingClass 6 - PHP Web Programming
Class 6 - PHP Web Programming
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP Strings
 
Data types in php
Data types in phpData types in php
Data types in php
 
Introduction to Web Programming: PHP vs ASP.NET
Introduction to Web Programming: PHP vs ASP.NETIntroduction to Web Programming: PHP vs ASP.NET
Introduction to Web Programming: PHP vs ASP.NET
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
BMSHanna_N_CV
BMSHanna_N_CVBMSHanna_N_CV
BMSHanna_N_CV
 
Trends and innovations in web development course
Trends and innovations in web development course Trends and innovations in web development course
Trends and innovations in web development course
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
League of extraordinary front end dev tools
League of extraordinary front end dev toolsLeague of extraordinary front end dev tools
League of extraordinary front end dev tools
 
Front-end Web Dev (HK) Info Session
Front-end Web Dev (HK) Info SessionFront-end Web Dev (HK) Info Session
Front-end Web Dev (HK) Info Session
 
Complete Web Development Course - Make Cash Earning Websites
Complete Web Development Course - Make Cash Earning WebsitesComplete Web Development Course - Make Cash Earning Websites
Complete Web Development Course - Make Cash Earning Websites
 
Introduction to Front End Engineering
Introduction to Front End EngineeringIntroduction to Front End Engineering
Introduction to Front End Engineering
 
Front-end Engineering Concepts
Front-end Engineering ConceptsFront-end Engineering Concepts
Front-end Engineering Concepts
 
PHP MVC Tutorial 2
PHP MVC Tutorial 2PHP MVC Tutorial 2
PHP MVC Tutorial 2
 
PHPUnit testing to Zend_Test
PHPUnit testing to Zend_TestPHPUnit testing to Zend_Test
PHPUnit testing to Zend_Test
 
Functions in php
Functions in phpFunctions in php
Functions in php
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
 

Similar to Class 2 - Introduction to PHP

MIND sweeping introduction to PHP
MIND sweeping introduction to PHPMIND sweeping introduction to PHP
MIND sweeping introduction to PHPBUDNET
 
Php basic for vit university
Php basic for vit universityPhp basic for vit university
Php basic for vit universityMandakini Kumari
 
php programming.pptx
php programming.pptxphp programming.pptx
php programming.pptxrani marri
 
PHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckPHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckrICh morrow
 
Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Michelangelo van Dam
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Muhamad Al Imran
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Muhamad Al Imran
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation TutorialLorna Mitchell
 
Introduction To Php For Wit2009
Introduction To Php For Wit2009Introduction To Php For Wit2009
Introduction To Php For Wit2009cwarren
 
PHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginnersPHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginnersMohammed Mushtaq Ahmed
 
Unit-1 PHP Basic1 of the understanding of php.pptx
Unit-1 PHP Basic1 of the understanding of php.pptxUnit-1 PHP Basic1 of the understanding of php.pptx
Unit-1 PHP Basic1 of the understanding of php.pptxAatifKhan84
 
PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackUAnshu Prateek
 
php fundamental
php fundamentalphp fundamental
php fundamentalzalatarunk
 
Php introduction with history of php
Php introduction with history of phpPhp introduction with history of php
Php introduction with history of phppooja bhandari
 

Similar to Class 2 - Introduction to PHP (20)

MIND sweeping introduction to PHP
MIND sweeping introduction to PHPMIND sweeping introduction to PHP
MIND sweeping introduction to PHP
 
Php basic for vit university
Php basic for vit universityPhp basic for vit university
Php basic for vit university
 
php programming.pptx
php programming.pptxphp programming.pptx
php programming.pptx
 
PHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckPHP from soup to nuts Course Deck
PHP from soup to nuts Course Deck
 
Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Php basics
Php basicsPhp basics
Php basics
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
 
Introduction To Php For Wit2009
Introduction To Php For Wit2009Introduction To Php For Wit2009
Introduction To Php For Wit2009
 
PHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginnersPHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginners
 
Php
PhpPhp
Php
 
Php + my sql
Php + my sqlPhp + my sql
Php + my sql
 
Unit-1 PHP Basic1 of the understanding of php.pptx
Unit-1 PHP Basic1 of the understanding of php.pptxUnit-1 PHP Basic1 of the understanding of php.pptx
Unit-1 PHP Basic1 of the understanding of php.pptx
 
PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackU
 
Wt unit 4 server side technology-2
Wt unit 4 server side technology-2Wt unit 4 server side technology-2
Wt unit 4 server side technology-2
 
php fundamental
php fundamentalphp fundamental
php fundamental
 
Php introduction with history of php
Php introduction with history of phpPhp introduction with history of php
Php introduction with history of php
 

Recently uploaded

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 

Recently uploaded (20)

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 

Class 2 - Introduction to PHP

  • 2. Outline • Why PHP? • Info Sources • A Walk Through PHP • Variables • Data Types • Type Casting • Constants • Operators • Control Structures • Assignment • What's Next?
  • 3. Why PHP? • Server-side scripting ( web development ) from basic to fully enterprise. ( the majority of facebook code is in PHP ). • Command-Line scripting. • Client-side GUI applications (using PHP GTK). • Supported on all Operating systems. • Can be embedded into HTML. • Easy to learn.
  • 4. Why PHP? • Around 21M websites are using PHP until 2007
  • 6. A Walk Through PHP • Opening/ closing tags : – <?php ?> (preferred) – <? ?> – <% %> – <script language="php"> </script> • Statements end with semi-colon ‘;’ : $x = 10;
  • 7. A Walk Through PHP • White spaces and Line breaks do not matter. • Comments : – # Single-line comments (or when a code block ends ‘?>’) – // Single-line comments (or when a code block ends ‘?>’) – /* Multi-line comments */ (can’t be nested)
  • 8. Variables • Start with a dollar sign ‘$’. • Can contain upper/ lower case letters, number and underscores. • Can’t start with a number (after the ‘$’ sign). • They are case sensitive.
  • 9. Variables • Examples: – Legal: • $name • $_name • $name_12 – Illegal: • $not valid • $12name • $| – These identifiers are not the same: ( $hi, $Hi ).
  • 10. Data Types PHP is weakly typed language. 1.Integer: – Example : • $x = 12000 • $y = +50 • $z = -30
  • 11. Data Types 1. Floating Point: – Examples: • $x = 0.45 • $y = +20.2 • $z = -40.11 • $k = +0.345E2 • $d = -0.234E-3
  • 12. Data Types 1. String: – Sequence of characters with an arbitrary length. – Examples: • $name = ‘Mohamed’; • $name = “Mohamed”; • $str = <<<EOD Example of string spanning multiple lines using heredoc syntax. EOD; • echo ‘here is it’; • print “line 1 n line2”; • $name = ‘john’; echo “Hello $name”;
  • 13. Data Types 1. Boolean: – true or false values. – Used in conditional statements. – Example : $value = true; If( $value == true ) // do something
  • 14. Data Types 1. Array: – A collection that holds a number of values. – Example: $x = array(“Hi”, “Hello”, 3, 4.01 ).
  • 15. Data Types 1. Objects: – A class is a definition of some variables and functions that maps to a real entity. – Example : class Person{ private $var=‘’; public function getVar(){ return $var; } }
  • 16. Data Types 1. Resource: – It is an identifier for an external connection or object (database or file handle).
  • 17. Data Types 1. NULL: – It is the no-value value. – Example: $x = 10; $x = NULL; //value is gone
  • 18. Type Casting <?php $foo = (float)'1'; // 1.0 $foo = (int)10.5; // 10 $foo = (boolean) 5; // true ?>
  • 19. Type Casting <?php $foo = "0"; // $foo is string $foo += 2; // $foo is now an integer (2) $foo = $foo + 1.3; // $foo is now a float (3.3) $foo = 5 + "10 Little Piggies"; // $foo is integer (15) $foo = 5 + "10 Small Pigs"; // $foo is integer (15) ?>
  • 20. Constants – Is an identifier (name) for a simple value. that value cannot change during the execution of the script. – Example: • define("FOO", "something"); // valid • define("2FOO", "something"); // not valid
  • 21. Operators – An operator is a symbol that takes arguments and returns a value. – Arithmetic Operators : Operator Description Example Result + Addition x=2 x+2 4 - Subtraction x=2 5-x 3 * Multiplication x=4 x*5 20 / Division 15/5 5/2 3 2.5 % Modulus (division remainder) 5%2 10%8 10%2 1 2 0 ++ Increment x=5 x++ x=6 -- Decrement x=5 x-- x=4
  • 22. Operators • Assignment Operators: Operator Example Is The Same As = x=y x=y += x+=y x=x+y -= x-=y x=x-y *= x*=y x=x*y /= x/=y x=x/y .= x.=y x=x.y %= x%=y x=x%y
  • 23. Operators • Comparison Operators: Operator Description Example == is equal to 5==8 returns false != is not equal 5!=8 returns true <> is not equal 5<>8 returns true > is greater than 5>8 returns false < is less than 5<8 returns true >= is greater than or equal to 5>=8 returns false <= is less than or equal to 5<=8 returns true === Identical to 5 === “5” returns false
  • 24. Operators • Logical Operators : Operator Description Example && And x=6 y=3 (x < 10 && y > 1) returns true || Or x=6 y=3 (x==5 || y==5) returns false ! not x=6 y=3 !(x==y) returns true
  • 25. Advanced trick • Variable variables : $x = "name"; $name = 10; echo $$x; // 10
  • 26. Control Structures • ‘If’ statement : <?php if ($a > $b) echo "a is bigger than b"; ?> • ‘else’ statement : <?php if ($a > $b) { echo "a is greater than b"; } else { echo "a is NOT greater than b"; } ?>
  • 27. Control Structures • ‘elseif’ / ‘else if’ : <?php if ($a > $b) { echo "a is bigger than b"; } elseif ($a == $b) { echo "a is equal to b"; } else { echo "a is smaller than b"; } ?>
  • 28. Demo
  • 29. Control Structures • ‘switch’ statement: – The switch statement is similar to a series of IF/else statements on the same expression. if ($i == 0) { echo "i equals 0"; } elseif ($i == 1) { echo "i equals 1"; } else { echo “i equals another value”; } switch ($i) { case 0: echo "i equals 0"; break; case 1: echo "i equals 1"; break; default: echo “i equals another value”; } =
  • 30. Control Structures • Loops: – ‘for’ – ‘while’ – ‘do while’ – ‘foreach’ (will be discussed more in Arrays)
  • 31. Control Structures • The ‘for’ loop: for( $i = 0; $i <= 5; $i++ ) { echo $i . " "; }
  • 32. Control Structures • The ‘while’ loop: $i = 0; While( $i < 5 ){ echo $i; $i++; }
  • 33. Control Structures • The ‘do while’ loop: $i = 0; do { echo $i; $i++; } while ($i < 5);
  • 34. Demo
  • 35. Control Structures • ‘break’ keyword : – break ends execution of the current for, foreach, while, do-while or switch structure. – Example: While( $x ){ If( $y ) break; echo $x; }
  • 36. Control Structures • ‘continue’ keyword : – continue is used within looping structures to skip the rest of the current loop iteration and continue execution at the condition evaluation and then the beginning of the next iteration. – Example: While( $x < 5 ){ If( $x == 2 ){ $x++; continue; } echo $x; $x++; }
  • 37. Assignment • Write a PHP snippet that will generate the following output : * *** ***** ******* ********* *********** ************* *************** ***************** *******************