SlideShare a Scribd company logo
Introduction to PHP
PHP
PHP Hypertext Pre-processor
‚PHP is a server side scripting language‛
“Personal home page”
Generate HTML
Get index.php
1
3
4
pass index.php to PHP
interpretor
5
WebServer
Index.php in interpreted
HTMl form
Browser
2
Get index.php from
hard disk
What you mean by hypertext Pre-processor?
Scripting Languages
• A ‚script‛ is a collection of program or sequence of instructions that is
interpreted or carried out by another program rather than by the computer
processor. Two types of scripting languages are
– Client-side Scripting Language
– Server-side Scripting Language
• In server-side scripting, (such as PHP, ASP) the script is processed by the
server Like: Apache, ColdFusion, ISAPI and Microsoft's IIS on Windows.
• Client-side scripting such as JavaScript runs on the web browser.
What you mean by server side scripting??
•
Generate HTML
Get index.php
1
3
4
pass index.php to PHP
interpretor
5
WebServer
Index.php in interpreted
HTMl form
Browser
2
Get index.php from
hard disk
PHP is server side scripting
language because the php code
runs on the server and returns
the result in html form to the
client browser
What you mean by client side scripting??
•
Generate HTML
Get index.php
1
3
4
pass index.php to PHP
interpretor
5
WebServer
Index.php in interpreted
HTMl form
Browser
2
Get index.php from
hard disk
Client side scripting is something
where code runs on client
side(browser). For eg checking
whether a HTML text field contains
data or not can be done by running
a script from browser itself
Creating a PHP page
How to create a PHP page
1. Install Wamp (Windows-Apache-Mysql-PHP)
2. Create a new folder within WampWWW folder with the name
you want to give your project
• Eg: C:WampWWWmyProject
3. Right click and Create a new text file with extention ‚.php‛
• Eg: index.php
How to run PHP program
1. Start Wamp Server
2. Open your browser and type localhost/myProject/
3. Most of the browsers load the file with name ‚index‛ automatically. So it
is recommended to have the name ‚index‛ for your home page
Getting started with PHP programming
PHP Syntax
 Structurally similar to C/C++
 Supports procedural and object-oriented paradigm (to some degree)
 All PHP statements end with a semi-colon
 Each PHP script must be enclosed in the reserved PHP tag
<?php
//PHP code goes here..
?>
Other PHP tags
<?php
... Code
?>
Standard Tags
<?
... Code
?>
<?= $variable ?>
<script language=“php”>
... Code
</script>
<%
... Code
%>
Short Tags
Script TagsASP Tags
Commenting
// comment single line
/* comment
multiple lines */
//comment single line
/* Comment
multiple Lines*/
# comment single line-shell style
C PHP
Data Types
Data types
• PHP supports many different data types, but they are generally
divided in two categories:
• Scalar
» boolean :A value that can only either be true or false
» Int :A signed numeric integer value
» float : A signed floating-point value
» string : A collection of binary data
• Composite.
» Arrays
» Objects
Type Casting
 echo ((0.1 + 0.7) * 10); //Outputs 8
 echo (int) ((0.1 + 0.7) * 10); //Outputs 7
• This happens because the result of this simple arithmetic
expression is stored internally as 7.999999 instead of 8; when the
value is converted to int, PHP simply truncates away the fractional
part, resulting in a rather significant error (12.5%, to be exact).
Variables
Declaring a variable
//Declaring a variable
Int a=10;
Char c=‘a’;
Float f=1.12;
//Every variable starts with ‚$‚sign
//No need of prior Declarations
$a=10;
$c=‘a’;
$f=1.12;
C PHP
Variables
• Variables are temporary storage containers.
• In PHP, a variable can contain any type of data, such as, for example,
strings, integers, floating numbers, objects and arrays.
• PHP is loosely typed, meaning that it will implicitly change the type of a
variable as needed, depending on the operation being performed on its
value.
• This contrasts with strongly typed languages, like C and Java, where
variables can only contain one type of data throughout their existence.
Variable Variables
• In PHP, it is also possible to create so-called variable variables.
That is a variable whose name is contained in another variable.
For eg:
$name = ’foo’;
$$name = ’bar’;
echo $foo; // Displays ’bar’
function myFunc()
{
echo ’myFunc!’;
}
$f = ’myFunc’;
$f(); // will call myFunc();
Determining If a Variable Exists
• There is an inbuilt method called isset() which will return true if a
variable exists and has a value other than null
$x=12;
echo isset ($x); // returns true
echo isset($y); // returns false
Constants
Declaring a constant
//Declaring a constant using ‘const’
const int a=10;
int const a=10;
//Declaring a constant using ‘#define’
#define TRUE 1
#define FALSE 0
#define NAME_SIZE 20
define(’name’, ’baabtra’);
define(’EMAIL’, ’davey@php.net’);
echo EMAIL; // Displays ’davey@php.net’
echo name.PHP_EOL.email;
// Displays ’baabtra;
‘davey@php.net’
C PHP
Constants
• Conversely to variables, constants are meant for defining immutable values.
• Constants can be accessed for any scope within a script; however, they can
only contain scalar values.
• The built-in PHP_EOL constant represents the ‚end of line‛ marker.
OutPut
output
Int a=10,b=25;
Printf(‚%d %d‛,a,b);
$a=10; $b=25
Printf(‚%d %d‛,$a,$b);
print $a;
print $b; //Cannot take multiple arguments
echo $a,$b; //Fast and commonly used
die(‚the end‛);
exit(‚the end‛); // both allows to terminate
the script’s output by outputting a string
C PHP
echo Vs print
• echo is a language construct ( Constructs
are elements that are built-into the language
and, therefore, follow special rules)
• echo doesnt have a return value
• print() is not a language construct. It
is an inbuilt function only
• Always return 1 once it print
someting
Control structures
Control Structures
Conditional Control Structures
• If
• If else
• Switch
Loops
For
While
Do while
Other
• Break
• Continue
‚Exactly the same as on left side‛
C PHP
functions
Functions
Int findSum(int a,int b)
{
Int c;
c=a+b;
Return c
}
findSum(10,15);
function findSum($a,$b)
{
$c=$a+$b;
Return $c;
}
findSum(10,15);
C PHP
Function arguments
• You can define any number of arguments and, in fact, you can pass an
arbitrary number of arguments to a function, regardless of how many you
specified in its declaration.PHP will not complain unless you provide fewer
arguments than you declared
Eg:
function greeting($arg1)
{
echo ‚hello $ arg1‛;
}
greeting(‚baabtra‛);
greeting(‚baabtra‛, ‛baabte‛);
greeting(); // ERROR
Function arguments
• You can make arguments optional by giving them a default value.
function hello($who = "World")
{
echo "Hello $who";
}
hello(‘baabtra’); // hello baabtra
hello(); // hello world
Function arguments
PHP provides three built-in functions to handle variable-length
argument lists:
– func_num_args() : return the total number of arguments
– func_get_arg() : return the argument at any index position
– func_get_args() : returns an array of all argument
Function arguments
function hello()
{
if (func_num_args() > 0)
{
$arg = func_get_arg(0); // The first argument is at position 0
echo "Hello $arg";
}
else
{
echo "Hello World";
}
}
hello("Reader"); // Displays "Hello Reader"
hello(); // Displays "Hello World“
Function return type
• In PHP functions even if you don’t return a value, PHP will still
cause your function to return NULL. So there is no concept of
‘void’
Strings
Char a*+=‚Baabtra‛;
Printf(‚Hello %s‛,a);
$a=‚Baabtra‛;
echo ‚Hello $a‛; //Output: Hello baabtra;
echo ‘Hello $a’; //Outputs : Hello $a
‚Strings will be continued in coming
chapters‛
C PHP
Arrays
Indexed Array
int a[]={1,2,3,4,5,6,7,8,9,10};
for(i=0;i<10;i++)
Printf(‚%d‛,a[i]);
Indexed Array / Enumerated array
$a=array(1,2,3,4,5,6,7,8,9,10)
for($i=0;$i<10;$i++)
echo $a[$i] ;
Associative Array
$a*‘name’+=‚John‛;
$a*‘age’+=24;
$a*‘mark’+=35.65;
‚Array will be continued in coming
chapters‛
C PHP
Operators
Operators
C
Arithmetic Operators
+, ++, -, --, *, /, %
Comparison Operators
==, !=, ===, !==, >, >=, < , <=
Logical Operators
&&, ||, !
Assignment Operators
=, +=, -=, *=, /=, %=
PHP
‚Supports all on left . In addition
PHP supports below operators as well‛
• Execution Operators
• String operators
• Type Operators
• Error Control Operators
• Bitwise Operators
• The backtick operator makes it possible to execute a shell command and
retrieve its output. For example, the following will cause the output of the
UNIX ls commandto be stored inside $a:
Eg : $a = ‘ls -l‘;
Execution operator (‘)
Don’t confuse the backtick operator with regular quotes (and, conversely, don’t
confuse the latter with the former!)
– The dot (.) operator is used to concatenate two strings
Eg1: $string=‚baabtra‛. ‚mentoring parner‛
Eg2: $string1=‚baabtra‛;
$string2=‚mentoring parner‛;
$string3=$string1.$string2;
String operators (.)
– Used to determine whether a variable is an instantiated object of a certain class or
an object of a class that inherits from a parent class
Eg: class ParentClass
{ }
class MyClass extends ParentClass
{ }
$a = new MyClass;
var_dump($a instanceof MyClass); // returns true as $a is an object of MyClass
var_dump($a instanceof ParentClass); // returns true as $a is an object of MyClass
which inherits parentClass
Type operators (instanceof )
Error suppression operator (@)
• When prepended to an expression, this operator causes PHP to ignore
almost all error messages that occur while that expression is being evaluated
Eg: $x = @mysql_connect(‘localhost’,’root’,’1234’);
• The code above will prevent the call to mysql_connect() from outputting an
error—provided that the function uses PHP’s own functionality for
reporting errors.
• Sadly, some libraries output their errors directly, bypassing PHP and,
therefore, make it much harder to manage with the error-control operator.
• Bitwise operators allow you to manipulate bits of data. All these operators are
designed to work only on integer numbers—therefore, the interpreter will attempt
to convert their operands to integers before executing them.
Bitwise Operators
& Bitwise AND. The result of the operation will be a value whose bits are set if they are set in
both operands, and unset otherwise.
| Bitwise OR. The result of the operation will be a value whose bits are set if they are set in
either operand (or both), and unset otherwise.
ˆ Bitwise XOR (exclusive OR). The result of the operation will be a value whose bits are set if
they are set in either operand, and unset otherwise.
<< Bitwise left shift. This operation shifts the left-hand operand’s bits to the left by a number of
positions equal to the right operand, inserting unset bits in the shifted positions
>> Bitwise right shift. This operation shifts the left-hand operand’s bits to the right by a number
of positions equal to the right operand, inserting unset bits in the shifted positions.
Questions?
‚A good question deserve a good grade…‛
End of day
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com

More Related Content

PPT
Introduction to php php++
PPTX
Php basics
PPT
PHP - Introduction to PHP
PPTX
Php.ppt
PPT
PPT
Introduction to PHP
PPTX
Dev traning 2016 basics of PHP
Introduction to php php++
Php basics
PHP - Introduction to PHP
Php.ppt
Introduction to PHP
Dev traning 2016 basics of PHP

What's hot (20)

PDF
07 Introduction to PHP #burningkeyboards
PPTX
php basics
PDF
Introduction to PHP - Basics of PHP
PPT
PHP Workshop Notes
PPTX
PHP slides
PPT
PHP - Introduction to PHP - Mazenet Solution
PDF
Introduction to php
ODP
PHP Basic
PDF
Introduction to php
PPT
PPTX
Constructor and encapsulation in php
PPTX
Basic of PHP
PPT
Php Lecture Notes
PPTX
PPT
Control Structures In Php 2
PPSX
PHP Comprehensive Overview
PPTX
Php Tutorial
PPT
Php(report)
PPT
PHP POWERPOINT SLIDES
PPT
Php i basic chapter 3
07 Introduction to PHP #burningkeyboards
php basics
Introduction to PHP - Basics of PHP
PHP Workshop Notes
PHP slides
PHP - Introduction to PHP - Mazenet Solution
Introduction to php
PHP Basic
Introduction to php
Constructor and encapsulation in php
Basic of PHP
Php Lecture Notes
Control Structures In Php 2
PHP Comprehensive Overview
Php Tutorial
Php(report)
PHP POWERPOINT SLIDES
Php i basic chapter 3
Ad

Viewers also liked (20)

PPTX
PHP Templating Systems
PPTX
MVC Frameworks for building PHP Web Applications
PPT
Why MVC?
PPT
01 Php Introduction
PDF
Startup #7 : how to get customers
PDF
PHP #1 : introduction
PPT
Introduction To PHP
PPT
Php Presentation
PDF
Introduction to PHP
PDF
Nnnnooemi pool riooss 1c
PPTX
Introduction à HTML 5
PPT
Html 5 introduction
PDF
Intro to html 5
PPTX
Introduction to html 5
PDF
Introduction to PHP H/MVC Frameworks by www.silicongulf.com
PDF
Grokking regex
PDF
Don't Fear the Regex - Northeast PHP 2015
PDF
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i
PPT
PHP Framework
PDF
Principles of MVC for PHP Developers
PHP Templating Systems
MVC Frameworks for building PHP Web Applications
Why MVC?
01 Php Introduction
Startup #7 : how to get customers
PHP #1 : introduction
Introduction To PHP
Php Presentation
Introduction to PHP
Nnnnooemi pool riooss 1c
Introduction à HTML 5
Html 5 introduction
Intro to html 5
Introduction to html 5
Introduction to PHP H/MVC Frameworks by www.silicongulf.com
Grokking regex
Don't Fear the Regex - Northeast PHP 2015
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i
PHP Framework
Principles of MVC for PHP Developers
Ad

Similar to Introduction to php basics (20)

PDF
WT_PHP_PART1.pdf
PPTX
Php intro by sami kz
PDF
Web Development Course: PHP lecture 1
PPTX
php Chapter 1.pptx
PDF
Programming in PHP Course Material BCA 6th Semester
PPTX
PHP2An introduction to Gnome.pptx.j.pptx
PPTX
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
PPT
Prersentation
PDF
Php introduction
PPTX
PHP Lecture 01 .pptx PHP Lecture 01 pptx
PDF
Wt unit 4 server side technology-2
PPT
PHP - Introduction to PHP Fundamentals
PPT
php41.ppt
PPT
PHP InterLevel.ppt
PPT
php-I-slides.ppt
PPTX
The basics of php for engeneering students
PDF
Introduction of PHP.pdf
PPT
Php i-slides
PPT
Php i-slides
WT_PHP_PART1.pdf
Php intro by sami kz
Web Development Course: PHP lecture 1
php Chapter 1.pptx
Programming in PHP Course Material BCA 6th Semester
PHP2An introduction to Gnome.pptx.j.pptx
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Prersentation
Php introduction
PHP Lecture 01 .pptx PHP Lecture 01 pptx
Wt unit 4 server side technology-2
PHP - Introduction to PHP Fundamentals
php41.ppt
PHP InterLevel.ppt
php-I-slides.ppt
The basics of php for engeneering students
Introduction of PHP.pdf
Php i-slides
Php i-slides

More from baabtra.com - No. 1 supplier of quality freshers (20)

PPTX
Agile methodology and scrum development
PDF
Acquiring new skills what you should know
PDF
Baabtra.com programming at school
PDF
99LMS for Enterprises - LMS that you will love
PPTX
Chapter 6 database normalisation
PPTX
Chapter 5 transactions and dcl statements
PPTX
Chapter 4 functions, views, indexing
PPTX
PPTX
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
PPTX
Chapter 1 introduction to sql server
PPTX
Chapter 1 introduction to sql server
Agile methodology and scrum development
Acquiring new skills what you should know
Baabtra.com programming at school
99LMS for Enterprises - LMS that you will love
Chapter 6 database normalisation
Chapter 5 transactions and dcl statements
Chapter 4 functions, views, indexing
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 1 introduction to sql server
Chapter 1 introduction to sql server

Recently uploaded (20)

PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
A Presentation on Artificial Intelligence
PDF
Approach and Philosophy of On baking technology
PDF
Modernizing your data center with Dell and AMD
PDF
cuic standard and advanced reporting.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Machine learning based COVID-19 study performance prediction
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Electronic commerce courselecture one. Pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Chapter 3 Spatial Domain Image Processing.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
A Presentation on Artificial Intelligence
Approach and Philosophy of On baking technology
Modernizing your data center with Dell and AMD
cuic standard and advanced reporting.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation_ Review paper, used for researhc scholars
Machine learning based COVID-19 study performance prediction
Building Integrated photovoltaic BIPV_UPV.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
MYSQL Presentation for SQL database connectivity
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Electronic commerce courselecture one. Pdf
NewMind AI Monthly Chronicles - July 2025
Diabetes mellitus diagnosis method based random forest with bat algorithm
“AI and Expert System Decision Support & Business Intelligence Systems”
The AUB Centre for AI in Media Proposal.docx
Empathic Computing: Creating Shared Understanding
Chapter 3 Spatial Domain Image Processing.pdf

Introduction to php basics

  • 2. PHP PHP Hypertext Pre-processor ‚PHP is a server side scripting language‛ “Personal home page”
  • 3. Generate HTML Get index.php 1 3 4 pass index.php to PHP interpretor 5 WebServer Index.php in interpreted HTMl form Browser 2 Get index.php from hard disk What you mean by hypertext Pre-processor?
  • 4. Scripting Languages • A ‚script‛ is a collection of program or sequence of instructions that is interpreted or carried out by another program rather than by the computer processor. Two types of scripting languages are – Client-side Scripting Language – Server-side Scripting Language • In server-side scripting, (such as PHP, ASP) the script is processed by the server Like: Apache, ColdFusion, ISAPI and Microsoft's IIS on Windows. • Client-side scripting such as JavaScript runs on the web browser.
  • 5. What you mean by server side scripting?? • Generate HTML Get index.php 1 3 4 pass index.php to PHP interpretor 5 WebServer Index.php in interpreted HTMl form Browser 2 Get index.php from hard disk PHP is server side scripting language because the php code runs on the server and returns the result in html form to the client browser
  • 6. What you mean by client side scripting?? • Generate HTML Get index.php 1 3 4 pass index.php to PHP interpretor 5 WebServer Index.php in interpreted HTMl form Browser 2 Get index.php from hard disk Client side scripting is something where code runs on client side(browser). For eg checking whether a HTML text field contains data or not can be done by running a script from browser itself
  • 8. How to create a PHP page 1. Install Wamp (Windows-Apache-Mysql-PHP) 2. Create a new folder within WampWWW folder with the name you want to give your project • Eg: C:WampWWWmyProject 3. Right click and Create a new text file with extention ‚.php‛ • Eg: index.php
  • 9. How to run PHP program 1. Start Wamp Server 2. Open your browser and type localhost/myProject/ 3. Most of the browsers load the file with name ‚index‛ automatically. So it is recommended to have the name ‚index‛ for your home page
  • 10. Getting started with PHP programming
  • 11. PHP Syntax  Structurally similar to C/C++  Supports procedural and object-oriented paradigm (to some degree)  All PHP statements end with a semi-colon  Each PHP script must be enclosed in the reserved PHP tag <?php //PHP code goes here.. ?>
  • 12. Other PHP tags <?php ... Code ?> Standard Tags <? ... Code ?> <?= $variable ?> <script language=“php”> ... Code </script> <% ... Code %> Short Tags Script TagsASP Tags
  • 13. Commenting // comment single line /* comment multiple lines */ //comment single line /* Comment multiple Lines*/ # comment single line-shell style C PHP
  • 15. Data types • PHP supports many different data types, but they are generally divided in two categories: • Scalar » boolean :A value that can only either be true or false » Int :A signed numeric integer value » float : A signed floating-point value » string : A collection of binary data • Composite. » Arrays » Objects
  • 16. Type Casting  echo ((0.1 + 0.7) * 10); //Outputs 8  echo (int) ((0.1 + 0.7) * 10); //Outputs 7 • This happens because the result of this simple arithmetic expression is stored internally as 7.999999 instead of 8; when the value is converted to int, PHP simply truncates away the fractional part, resulting in a rather significant error (12.5%, to be exact).
  • 18. Declaring a variable //Declaring a variable Int a=10; Char c=‘a’; Float f=1.12; //Every variable starts with ‚$‚sign //No need of prior Declarations $a=10; $c=‘a’; $f=1.12; C PHP
  • 19. Variables • Variables are temporary storage containers. • In PHP, a variable can contain any type of data, such as, for example, strings, integers, floating numbers, objects and arrays. • PHP is loosely typed, meaning that it will implicitly change the type of a variable as needed, depending on the operation being performed on its value. • This contrasts with strongly typed languages, like C and Java, where variables can only contain one type of data throughout their existence.
  • 20. Variable Variables • In PHP, it is also possible to create so-called variable variables. That is a variable whose name is contained in another variable. For eg: $name = ’foo’; $$name = ’bar’; echo $foo; // Displays ’bar’ function myFunc() { echo ’myFunc!’; } $f = ’myFunc’; $f(); // will call myFunc();
  • 21. Determining If a Variable Exists • There is an inbuilt method called isset() which will return true if a variable exists and has a value other than null $x=12; echo isset ($x); // returns true echo isset($y); // returns false
  • 23. Declaring a constant //Declaring a constant using ‘const’ const int a=10; int const a=10; //Declaring a constant using ‘#define’ #define TRUE 1 #define FALSE 0 #define NAME_SIZE 20 define(’name’, ’baabtra’); define(’EMAIL’, ’davey@php.net’); echo EMAIL; // Displays ’davey@php.net’ echo name.PHP_EOL.email; // Displays ’baabtra; ‘davey@php.net’ C PHP
  • 24. Constants • Conversely to variables, constants are meant for defining immutable values. • Constants can be accessed for any scope within a script; however, they can only contain scalar values. • The built-in PHP_EOL constant represents the ‚end of line‛ marker.
  • 26. output Int a=10,b=25; Printf(‚%d %d‛,a,b); $a=10; $b=25 Printf(‚%d %d‛,$a,$b); print $a; print $b; //Cannot take multiple arguments echo $a,$b; //Fast and commonly used die(‚the end‛); exit(‚the end‛); // both allows to terminate the script’s output by outputting a string C PHP
  • 27. echo Vs print • echo is a language construct ( Constructs are elements that are built-into the language and, therefore, follow special rules) • echo doesnt have a return value • print() is not a language construct. It is an inbuilt function only • Always return 1 once it print someting
  • 29. Control Structures Conditional Control Structures • If • If else • Switch Loops For While Do while Other • Break • Continue ‚Exactly the same as on left side‛ C PHP
  • 31. Functions Int findSum(int a,int b) { Int c; c=a+b; Return c } findSum(10,15); function findSum($a,$b) { $c=$a+$b; Return $c; } findSum(10,15); C PHP
  • 32. Function arguments • You can define any number of arguments and, in fact, you can pass an arbitrary number of arguments to a function, regardless of how many you specified in its declaration.PHP will not complain unless you provide fewer arguments than you declared Eg: function greeting($arg1) { echo ‚hello $ arg1‛; } greeting(‚baabtra‛); greeting(‚baabtra‛, ‛baabte‛); greeting(); // ERROR
  • 33. Function arguments • You can make arguments optional by giving them a default value. function hello($who = "World") { echo "Hello $who"; } hello(‘baabtra’); // hello baabtra hello(); // hello world
  • 34. Function arguments PHP provides three built-in functions to handle variable-length argument lists: – func_num_args() : return the total number of arguments – func_get_arg() : return the argument at any index position – func_get_args() : returns an array of all argument
  • 35. Function arguments function hello() { if (func_num_args() > 0) { $arg = func_get_arg(0); // The first argument is at position 0 echo "Hello $arg"; } else { echo "Hello World"; } } hello("Reader"); // Displays "Hello Reader" hello(); // Displays "Hello World“
  • 36. Function return type • In PHP functions even if you don’t return a value, PHP will still cause your function to return NULL. So there is no concept of ‘void’
  • 37. Strings Char a*+=‚Baabtra‛; Printf(‚Hello %s‛,a); $a=‚Baabtra‛; echo ‚Hello $a‛; //Output: Hello baabtra; echo ‘Hello $a’; //Outputs : Hello $a ‚Strings will be continued in coming chapters‛ C PHP
  • 38. Arrays Indexed Array int a[]={1,2,3,4,5,6,7,8,9,10}; for(i=0;i<10;i++) Printf(‚%d‛,a[i]); Indexed Array / Enumerated array $a=array(1,2,3,4,5,6,7,8,9,10) for($i=0;$i<10;$i++) echo $a[$i] ; Associative Array $a*‘name’+=‚John‛; $a*‘age’+=24; $a*‘mark’+=35.65; ‚Array will be continued in coming chapters‛ C PHP
  • 40. Operators C Arithmetic Operators +, ++, -, --, *, /, % Comparison Operators ==, !=, ===, !==, >, >=, < , <= Logical Operators &&, ||, ! Assignment Operators =, +=, -=, *=, /=, %= PHP ‚Supports all on left . In addition PHP supports below operators as well‛ • Execution Operators • String operators • Type Operators • Error Control Operators • Bitwise Operators
  • 41. • The backtick operator makes it possible to execute a shell command and retrieve its output. For example, the following will cause the output of the UNIX ls commandto be stored inside $a: Eg : $a = ‘ls -l‘; Execution operator (‘) Don’t confuse the backtick operator with regular quotes (and, conversely, don’t confuse the latter with the former!)
  • 42. – The dot (.) operator is used to concatenate two strings Eg1: $string=‚baabtra‛. ‚mentoring parner‛ Eg2: $string1=‚baabtra‛; $string2=‚mentoring parner‛; $string3=$string1.$string2; String operators (.)
  • 43. – Used to determine whether a variable is an instantiated object of a certain class or an object of a class that inherits from a parent class Eg: class ParentClass { } class MyClass extends ParentClass { } $a = new MyClass; var_dump($a instanceof MyClass); // returns true as $a is an object of MyClass var_dump($a instanceof ParentClass); // returns true as $a is an object of MyClass which inherits parentClass Type operators (instanceof )
  • 44. Error suppression operator (@) • When prepended to an expression, this operator causes PHP to ignore almost all error messages that occur while that expression is being evaluated Eg: $x = @mysql_connect(‘localhost’,’root’,’1234’); • The code above will prevent the call to mysql_connect() from outputting an error—provided that the function uses PHP’s own functionality for reporting errors. • Sadly, some libraries output their errors directly, bypassing PHP and, therefore, make it much harder to manage with the error-control operator.
  • 45. • Bitwise operators allow you to manipulate bits of data. All these operators are designed to work only on integer numbers—therefore, the interpreter will attempt to convert their operands to integers before executing them. Bitwise Operators & Bitwise AND. The result of the operation will be a value whose bits are set if they are set in both operands, and unset otherwise. | Bitwise OR. The result of the operation will be a value whose bits are set if they are set in either operand (or both), and unset otherwise. ˆ Bitwise XOR (exclusive OR). The result of the operation will be a value whose bits are set if they are set in either operand, and unset otherwise. << Bitwise left shift. This operation shifts the left-hand operand’s bits to the left by a number of positions equal to the right operand, inserting unset bits in the shifted positions >> Bitwise right shift. This operation shifts the left-hand operand’s bits to the right by a number of positions equal to the right operand, inserting unset bits in the shifted positions.
  • 46. Questions? ‚A good question deserve a good grade…‛
  • 48. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com