SlideShare a Scribd company logo
PHP -  Introduction to PHP Functions
Introduction to PHPIntroduction to PHP
FunctionsFunctions
To function or not to function...To function or not to function...
• Organize your code into “paragraphs” - capture a
complete thought and “name it”
• Don’t repeat yourself - make it work once and then reuse
it
• If something gets too long or complex, break up logical
chunks and put those chunks in functions
• Make a library of common stuff that you do over and
over - perhaps share this with your friends...
Built-InBuilt-In FunctionsFunctions......
• Much of the power of PHP comes from its built-in
functions
echo strrev(" .dlrow olleH");
echo str_repeat("Hip ", 2);
echo strtoupper("hooray!");
echo "n";
Hello world.
Hip Hip
HOORAY!
PHP Documentation - GooglePHP Documentation - Google
One Heck of aOne Heck of a FunctionFunction..
• PHP is a very configurable system and has lots of
capabilities that can be plugged in.
• The phpinfo() function prints out the internal configuration
capabilities of your particular PHP installation
<?php
phpinfo();
?>
PHP -  Introduction to PHP Functions
Defining Your OwnDefining Your Own FunctionsFunctions
• We use the function keyword to define a function, we name the function
and take optional argument variables. The body of the function is in a
block of code { }
function greet() {
print "Hellon";
}
greet();
greet();
greet();
Hello
Hello
Hello
Choosing Function NamesChoosing Function Names
• Much like variable names - but do not start with a dollar
sign
o Start with a letter or underscore - consist of letters, numbers, and underscores ( _ )
• Avoid built in function names
• Case does not matter – but please do not take
advantage of this
ReturnReturn ValuesValues
• Often a function will take its arguments, do some
computation and return a value to be used as the value of
the function call in the calling expression. The return
keyword is used for this.
function greeting() {
return "Hello";
}
print greeting() . " Glennn";
print greeting() . " Sallyn";
Hello Glenn
Hello Sally
ArgumentsArguments
• Functions can choose to accept optional arguments. Within the
function definition the variable names are effectively "aliases" to
the values passed in when the function is called.
function howdy($lang) {
if ( $lang == 'es' ) return "Hola";
if ( $lang == 'fr' ) return "Bonjour";
return "Hello";
}
print howdy('es') . " Glennn";
print howdy('fr') . " Sallyn";
Hola Glenn
Bonjour Sally
Optional ArgumentsOptional Arguments
• Arguments can have defaults and so can be omitted
function howdy($lang='es') {
if ( $lang == 'es' ) return "Hola";
if ( $lang == 'fr' ) return "Bonjour";
return "Hello";
}
print howdy() . " Glennn";
print howdy('fr') . " Sallyn";
Hola Glenn
Bonjour Sally
Call By ValueCall By Value
• The argument variable within the function is an "alias" to the
actual variable
• But even further, the alias is to a *copy* of the actual
variable in the function call
function double($alias) {
$alias = $alias * 2;
return $alias;
}
$val = 10;
$dval = double($val);
echo "Value = $val Doubled = $dvaln";
Value = 10 Doubled = 20
Call ByCall By ReferenceReference
• Sometimes we want a function to change one of its
arguments - so we indicate that an argument is "by
reference" using ( & )
function triple(&$realthing) {
$realthing = $realthing * 3;
}
$val = 10;
triple($val);
echo "Triple = $valn";
Triple = 30
Variable ScopeVariable Scope
• In general, variable names used inside of function code, do
not mix with the variables outside of the function. They are
walled-off from the rest of the code. This is done because you
want to avoid "unexpected" side effects if two programmers
use the same variable name in different parts of the code.
• We call this "name spacing" the variables. The function
variables are in one "name space" whilst the main variables
are in another "name space"
• Like little padded cells of names - like silos to keep things
spearate
Normal Scope (isolated)Normal Scope (isolated)
function tryzap() {
$val = 100;
}
$val = 10;
tryzap();
echo "TryZap = $valn";
TryZap = 10
Global Scope (common)Global Scope (common)
function dozap() {
global $val;
$val = 100;
}
$val = 10;
dozap();
echo "DoZap = $valn";
DoZap = 100
Global Variables – UseGlobal Variables – Use
RarelyRarely
• Passing variable in as parameter
• Passing value back as return value
• Passing variable in by reference
• If you use Global Variables use really long names with
nice unique prefixes
global $LastOAuthBodyBaseString;
global $LAST_OAUTH_BODY_BASE_STRING;
Programming in MultipleProgramming in Multiple
FilesFiles
Multiple FilesMultiple Files
• When your programs get large enough, you may want to
break them into multiple files to allow some common bits
to be reused in many different files.
PHP -  Introduction to PHP Functions
<html>
<head>
<?php include("header.php"); ?>
</head>
<body>
<?php include("nav.php"); ?>
<div id="main">
.
.
.
</div>
<?php include("footer.php"); ?>
</body>
</html>
<html>
<head>
<?php include("header.php"); ?>
</head>
<body>
<?php include("nav.php"); ?>
<div id="main">
<iframeheight="4600" width="100%" frameborder="0"
marginwidth="0"marginheight="0" scrolling="auto"src="software.php"></iframe>
</div>
<?php include("footer.php"); ?>
</body>
</html>
IncludingIncluding files in PHPfiles in PHP
• include "header.php"; - Pull the file in here
• include_once "header.php"; - Pull the file in here unless it has
already been pulled in before
• require "header.php"; - Pull in the file here and die if it is missing
• require_once "header.php"; - You can guess what this means...
• These can look like functions - require_once("header.php");
Coping with Missing BitsCoping with Missing Bits
• Sometimes depending on the version or configuration of a
particular PHP instance, some functions may be missing.
We can check that.
if (function_exists("array_combine")){
echo "Function exists";
} else {
echo "Function does not exist";
}
SummarySummary
• Built-in functions
• Making new functions
• Arguments - pass by value and pass by reference
• Including and requiring files
• Checking to see if functions are present...
Acknowledgements / ContributionsAcknowledgements / Contributions
These slides are Copyright 2010- Charles R. Severance (www.dr-chuck.com) as
part of www.php-intro.com and made available under a Creative Commons
Attribution 4.0 License. Please maintain this last slide in all copies of the document
to comply with the attribution requirements of the license. If you make a change,
feel free to add your name and organization to the list of contributors on this page
as you republish the materials.
Initial Development: Charles Severance, University of Michigan School of
Information
Insert new Contributors and Translators here including names and dates
ThankThank You !!!You !!!
For More Information click below link:
Follow Us on:
http://
vibranttechnologies.co.in/php-classes-in-mumbai.html

More Related Content

What's hot (20)

Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
Vineet Kumar Saini
 
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
 
Introduction To PHP
Introduction To PHPIntroduction To PHP
Introduction To PHP
Shweta A
 
Php mysql
Php mysqlPhp mysql
Php mysql
Shehrevar Davierwala
 
Constructor and encapsulation in php
Constructor and encapsulation in phpConstructor and encapsulation in php
Constructor and encapsulation in php
SHIVANI SONI
 
Dev traning 2016 basics of PHP
Dev traning 2016   basics of PHPDev traning 2016   basics of PHP
Dev traning 2016 basics of PHP
Sacheen Dhanjie
 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
Santhiya Grace
 
Php basics
Php basicsPhp basics
Php basics
Jamshid Hashimi
 
Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting language
Elmer Concepcion Jr.
 
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop Notes
Pamela Fox
 
PHP
PHPPHP
PHP
sometech
 
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
Digital Insights - Digital Marketing Agency
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
Denis Ristic
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
Muhamad Al Imran
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
baabtra.com - No. 1 supplier of quality freshers
 
PHP MySQL Workshop - facehook
PHP MySQL Workshop - facehookPHP MySQL Workshop - facehook
PHP MySQL Workshop - facehook
Shashank Skills Academy
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Jussi Pohjolainen
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
Anjan Banda
 
Prersentation
PrersentationPrersentation
Prersentation
Ashwin Deora
 

Viewers also liked (7)

Lessons Learned - Building YDN
Lessons Learned - Building YDNLessons Learned - Building YDN
Lessons Learned - Building YDN
removed_90b14f0ccacc165c72857a08cfe7f775
 
Loops PHP 04
Loops PHP 04Loops PHP 04
Loops PHP 04
mohamedsaad24
 
Php introduction
Php introductionPhp introduction
Php introduction
krishnapriya Tadepalli
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Collaboration Technologies
 
Implementing DDD Concepts in PHP
Implementing DDD Concepts in PHPImplementing DDD Concepts in PHP
Implementing DDD Concepts in PHP
Steve Rhoades
 
01 Php Introduction
01 Php Introduction01 Php Introduction
01 Php Introduction
Geshan Manandhar
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Bradley Holt
 
Ad

Similar to PHP - Introduction to PHP Functions (20)

PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.ppt
Jamers2
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.ppt
ShishirKantSingh1
 
php
phpphp
php
Ramki Kv
 
Php introduction with history of php
Php introduction with history of phpPhp introduction with history of php
Php introduction with history of php
pooja bhandari
 
php fundamental
php fundamentalphp fundamental
php fundamental
zalatarunk
 
05php
05php05php
05php
sahilshamrma08
 
MIND sweeping introduction to PHP
MIND sweeping introduction to PHPMIND sweeping introduction to PHP
MIND sweeping introduction to PHP
BUDNET
 
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
rICh morrow
 
PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackU
Anshu Prateek
 
function in php using like three type of function
function in php using  like three type of functionfunction in php using  like three type of function
function in php using like three type of function
vishal choudhary
 
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
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
Php classes in mumbai
Php classes in mumbaiPhp classes in mumbai
Php classes in mumbai
Vibrant Technologies & Computers
 
05php
05php05php
05php
anshkhurana01
 
rtwerewr
rtwerewrrtwerewr
rtwerewr
esolinhighered
 
05php
05php05php
05php
Shahid Usman
 
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
Unit 5-PHP  Declaring variables, data types, array, string, operators, Expres...Unit 5-PHP  Declaring variables, data types, array, string, operators, Expres...
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
DRambabu3
 
Php course-in-navimumbai
Php course-in-navimumbaiPhp course-in-navimumbai
Php course-in-navimumbai
vibrantuser
 
function in php like control loop and its uses
function in php like control loop and its usesfunction in php like control loop and its uses
function in php like control loop and its uses
vishal choudhary
 
Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)
Damien Seguy
 
Object Oriented PHP - PART-2
Object Oriented PHP - PART-2Object Oriented PHP - PART-2
Object Oriented PHP - PART-2
Jalpesh Vasa
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.ppt
Jamers2
 
Php introduction with history of php
Php introduction with history of phpPhp introduction with history of php
Php introduction with history of php
pooja bhandari
 
php fundamental
php fundamentalphp fundamental
php fundamental
zalatarunk
 
MIND sweeping introduction to PHP
MIND sweeping introduction to PHPMIND sweeping introduction to PHP
MIND sweeping introduction to PHP
BUDNET
 
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
rICh morrow
 
PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackU
Anshu Prateek
 
function in php using like three type of function
function in php using  like three type of functionfunction in php using  like three type of function
function in php using like three type of function
vishal choudhary
 
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
Unit 5-PHP  Declaring variables, data types, array, string, operators, Expres...Unit 5-PHP  Declaring variables, data types, array, string, operators, Expres...
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
DRambabu3
 
Php course-in-navimumbai
Php course-in-navimumbaiPhp course-in-navimumbai
Php course-in-navimumbai
vibrantuser
 
function in php like control loop and its uses
function in php like control loop and its usesfunction in php like control loop and its uses
function in php like control loop and its uses
vishal choudhary
 
Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)Preparing for the next PHP version (5.6)
Preparing for the next PHP version (5.6)
Damien Seguy
 
Object Oriented PHP - PART-2
Object Oriented PHP - PART-2Object Oriented PHP - PART-2
Object Oriented PHP - PART-2
Jalpesh Vasa
 
Ad

More from Vibrant Technologies & Computers (20)

Buisness analyst business analysis overview ppt 5
Buisness analyst business analysis overview ppt 5Buisness analyst business analysis overview ppt 5
Buisness analyst business analysis overview ppt 5
Vibrant Technologies & Computers
 
SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables  SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables
Vibrant Technologies & Computers
 
SQL- Introduction to MySQL
SQL- Introduction to MySQLSQL- Introduction to MySQL
SQL- Introduction to MySQL
Vibrant Technologies & Computers
 
SQL- Introduction to SQL database
SQL- Introduction to SQL database SQL- Introduction to SQL database
SQL- Introduction to SQL database
Vibrant Technologies & Computers
 
ITIL - introduction to ITIL
ITIL - introduction to ITILITIL - introduction to ITIL
ITIL - introduction to ITIL
Vibrant Technologies & Computers
 
Salesforce - Introduction to Security & Access
Salesforce -  Introduction to Security & Access Salesforce -  Introduction to Security & Access
Salesforce - Introduction to Security & Access
Vibrant Technologies & Computers
 
Data ware housing- Introduction to olap .
Data ware housing- Introduction to  olap .Data ware housing- Introduction to  olap .
Data ware housing- Introduction to olap .
Vibrant Technologies & Computers
 
Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.
Vibrant Technologies & Computers
 
Data ware housing- Introduction to data ware housing
Data ware housing- Introduction to data ware housingData ware housing- Introduction to data ware housing
Data ware housing- Introduction to data ware housing
Vibrant Technologies & Computers
 
Salesforce - classification of cloud computing
Salesforce - classification of cloud computingSalesforce - classification of cloud computing
Salesforce - classification of cloud computing
Vibrant Technologies & Computers
 
Salesforce - cloud computing fundamental
Salesforce - cloud computing fundamentalSalesforce - cloud computing fundamental
Salesforce - cloud computing fundamental
Vibrant Technologies & Computers
 
SQL- Introduction to PL/SQL
SQL- Introduction to  PL/SQLSQL- Introduction to  PL/SQL
SQL- Introduction to PL/SQL
Vibrant Technologies & Computers
 
SQL- Introduction to advanced sql concepts
SQL- Introduction to  advanced sql conceptsSQL- Introduction to  advanced sql concepts
SQL- Introduction to advanced sql concepts
Vibrant Technologies & Computers
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
Vibrant Technologies & Computers
 
SQL- Introduction to SQL Set Operations
SQL- Introduction to SQL Set OperationsSQL- Introduction to SQL Set Operations
SQL- Introduction to SQL Set Operations
Vibrant Technologies & Computers
 
Sas - Introduction to designing the data mart
Sas - Introduction to designing the data martSas - Introduction to designing the data mart
Sas - Introduction to designing the data mart
Vibrant Technologies & Computers
 
Sas - Introduction to working under change management
Sas - Introduction to working under change managementSas - Introduction to working under change management
Sas - Introduction to working under change management
Vibrant Technologies & Computers
 
SAS - overview of SAS
SAS - overview of SASSAS - overview of SAS
SAS - overview of SAS
Vibrant Technologies & Computers
 
Teradata - Architecture of Teradata
Teradata - Architecture of TeradataTeradata - Architecture of Teradata
Teradata - Architecture of Teradata
Vibrant Technologies & Computers
 
Teradata - Restoring Data
Teradata - Restoring Data Teradata - Restoring Data
Teradata - Restoring Data
Vibrant Technologies & Computers
 
Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.
Vibrant Technologies & Computers
 

Recently uploaded (20)

AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training RoadblocksDown the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUEIntroduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
Domino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use CasesDomino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use Cases
panagenda
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOMEstablish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Anchore
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdfEdge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
How to Detect Outliers in IBM SPSS Statistics.pptx
How to Detect Outliers in IBM SPSS Statistics.pptxHow to Detect Outliers in IBM SPSS Statistics.pptx
How to Detect Outliers in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdfArtificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training RoadblocksDown the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Domino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use CasesDomino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use Cases
panagenda
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOMEstablish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Anchore
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdfEdge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
How to Detect Outliers in IBM SPSS Statistics.pptx
How to Detect Outliers in IBM SPSS Statistics.pptxHow to Detect Outliers in IBM SPSS Statistics.pptx
How to Detect Outliers in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdfArtificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 

PHP - Introduction to PHP Functions

  • 2. Introduction to PHPIntroduction to PHP FunctionsFunctions
  • 3. To function or not to function...To function or not to function... • Organize your code into “paragraphs” - capture a complete thought and “name it” • Don’t repeat yourself - make it work once and then reuse it • If something gets too long or complex, break up logical chunks and put those chunks in functions • Make a library of common stuff that you do over and over - perhaps share this with your friends...
  • 4. Built-InBuilt-In FunctionsFunctions...... • Much of the power of PHP comes from its built-in functions echo strrev(" .dlrow olleH"); echo str_repeat("Hip ", 2); echo strtoupper("hooray!"); echo "n"; Hello world. Hip Hip HOORAY!
  • 5. PHP Documentation - GooglePHP Documentation - Google
  • 6. One Heck of aOne Heck of a FunctionFunction.. • PHP is a very configurable system and has lots of capabilities that can be plugged in. • The phpinfo() function prints out the internal configuration capabilities of your particular PHP installation <?php phpinfo(); ?>
  • 8. Defining Your OwnDefining Your Own FunctionsFunctions • We use the function keyword to define a function, we name the function and take optional argument variables. The body of the function is in a block of code { } function greet() { print "Hellon"; } greet(); greet(); greet(); Hello Hello Hello
  • 9. Choosing Function NamesChoosing Function Names • Much like variable names - but do not start with a dollar sign o Start with a letter or underscore - consist of letters, numbers, and underscores ( _ ) • Avoid built in function names • Case does not matter – but please do not take advantage of this
  • 10. ReturnReturn ValuesValues • Often a function will take its arguments, do some computation and return a value to be used as the value of the function call in the calling expression. The return keyword is used for this. function greeting() { return "Hello"; } print greeting() . " Glennn"; print greeting() . " Sallyn"; Hello Glenn Hello Sally
  • 11. ArgumentsArguments • Functions can choose to accept optional arguments. Within the function definition the variable names are effectively "aliases" to the values passed in when the function is called. function howdy($lang) { if ( $lang == 'es' ) return "Hola"; if ( $lang == 'fr' ) return "Bonjour"; return "Hello"; } print howdy('es') . " Glennn"; print howdy('fr') . " Sallyn"; Hola Glenn Bonjour Sally
  • 12. Optional ArgumentsOptional Arguments • Arguments can have defaults and so can be omitted function howdy($lang='es') { if ( $lang == 'es' ) return "Hola"; if ( $lang == 'fr' ) return "Bonjour"; return "Hello"; } print howdy() . " Glennn"; print howdy('fr') . " Sallyn"; Hola Glenn Bonjour Sally
  • 13. Call By ValueCall By Value • The argument variable within the function is an "alias" to the actual variable • But even further, the alias is to a *copy* of the actual variable in the function call function double($alias) { $alias = $alias * 2; return $alias; } $val = 10; $dval = double($val); echo "Value = $val Doubled = $dvaln"; Value = 10 Doubled = 20
  • 14. Call ByCall By ReferenceReference • Sometimes we want a function to change one of its arguments - so we indicate that an argument is "by reference" using ( & ) function triple(&$realthing) { $realthing = $realthing * 3; } $val = 10; triple($val); echo "Triple = $valn"; Triple = 30
  • 15. Variable ScopeVariable Scope • In general, variable names used inside of function code, do not mix with the variables outside of the function. They are walled-off from the rest of the code. This is done because you want to avoid "unexpected" side effects if two programmers use the same variable name in different parts of the code. • We call this "name spacing" the variables. The function variables are in one "name space" whilst the main variables are in another "name space" • Like little padded cells of names - like silos to keep things spearate
  • 16. Normal Scope (isolated)Normal Scope (isolated) function tryzap() { $val = 100; } $val = 10; tryzap(); echo "TryZap = $valn"; TryZap = 10
  • 17. Global Scope (common)Global Scope (common) function dozap() { global $val; $val = 100; } $val = 10; dozap(); echo "DoZap = $valn"; DoZap = 100
  • 18. Global Variables – UseGlobal Variables – Use RarelyRarely • Passing variable in as parameter • Passing value back as return value • Passing variable in by reference • If you use Global Variables use really long names with nice unique prefixes global $LastOAuthBodyBaseString; global $LAST_OAUTH_BODY_BASE_STRING;
  • 19. Programming in MultipleProgramming in Multiple FilesFiles
  • 20. Multiple FilesMultiple Files • When your programs get large enough, you may want to break them into multiple files to allow some common bits to be reused in many different files.
  • 22. <html> <head> <?php include("header.php"); ?> </head> <body> <?php include("nav.php"); ?> <div id="main"> . . . </div> <?php include("footer.php"); ?> </body> </html>
  • 23. <html> <head> <?php include("header.php"); ?> </head> <body> <?php include("nav.php"); ?> <div id="main"> <iframeheight="4600" width="100%" frameborder="0" marginwidth="0"marginheight="0" scrolling="auto"src="software.php"></iframe> </div> <?php include("footer.php"); ?> </body> </html>
  • 24. IncludingIncluding files in PHPfiles in PHP • include "header.php"; - Pull the file in here • include_once "header.php"; - Pull the file in here unless it has already been pulled in before • require "header.php"; - Pull in the file here and die if it is missing • require_once "header.php"; - You can guess what this means... • These can look like functions - require_once("header.php");
  • 25. Coping with Missing BitsCoping with Missing Bits • Sometimes depending on the version or configuration of a particular PHP instance, some functions may be missing. We can check that. if (function_exists("array_combine")){ echo "Function exists"; } else { echo "Function does not exist"; }
  • 26. SummarySummary • Built-in functions • Making new functions • Arguments - pass by value and pass by reference • Including and requiring files • Checking to see if functions are present...
  • 27. Acknowledgements / ContributionsAcknowledgements / Contributions These slides are Copyright 2010- Charles R. Severance (www.dr-chuck.com) as part of www.php-intro.com and made available under a Creative Commons Attribution 4.0 License. Please maintain this last slide in all copies of the document to comply with the attribution requirements of the license. If you make a change, feel free to add your name and organization to the list of contributors on this page as you republish the materials. Initial Development: Charles Severance, University of Michigan School of Information Insert new Contributors and Translators here including names and dates
  • 28. ThankThank You !!!You !!! For More Information click below link: Follow Us on: http:// vibranttechnologies.co.in/php-classes-in-mumbai.html

Editor's Notes

  • #28: Note from Chuck. Please retain and maintain this page as you remix and republish these materials. Please add any of your own improvements or contributions.