SlideShare uma empresa Scribd logo
1 de 31
PHP Intermediate
Jamshid Hashimi
Trainer, Cresco Solution
http://www.jamshidhashimi.com
jamshid@netlinks.af
@jamshidhashimi
ajamshidhashimi
Afghanistan Workforce
Development Program
Agenda
• Arrays
• Loop
– For statement
– Foreach statement
– While statement
– Do While statement
• PHP Functions
• Get & Post Variable
• Difference between PHP 4 & PHP 5
• Exercise!
Arrays
• An array is a special variable, which can hold
more than one value at a time.
• array — Create an array
• Multidimensional Arrays
$arr = array("a" => "orange", "b" =>
"banana", "c" => "apple");
$fruits = array (
"fruits" => array("a" => "orange", "b" => "
banana", "c" => "apple"),
"numbers" => array(1, 2, 3, 4, 5, 6),
"holes" => array("first", 5 => "second", "
third")
);
Arrays: count()
• count — Count all elements in an array, or
something in an object
$arr = array("Kabul", "Balkh", "Herat",
"Qandahar");
echo count($arr);
> 4
Arrays: array_slice()
• array_slice — Extract a slice of the array
$arr = array("Kabul", "Balkh", "Herat",
"Qandahar");
$new_arr = array_slice($arr,1,2);
print_r($new_arr);
> Array ( [0] => Balkh [1] => Herat )
Arrays: array_reverse()
• array_reverse — Return an array with
elements in reverse order
$arr = array("Kabul", "Balkh", "Herat",
"Qandahar");
$new_arr = array_reverse($arr);
print_r($new_arr);
> Array ( [0] => Qandahar [1] => Herat [2]
=> Balkh [3] => Kabul )
Arrays: array_keys()
• array_keys — Return all the keys or a subset of
the keys of an array
$arr = array("Kabul", "Balkh", "Herat",
"Qandahar");
$new_arr = array_keys($arr);
print_r($new_arr);
> Array ( [0] => 0 [1] => 1 [2] => 2 [3] =>
3 )
Arrays: in_array()
• in_array — Checks if a value exists in an array
$arr = array("Kabul", "Balkh", "Herat",
"Qandahar");
if(in_array("Kabul",$arr)){
echo "Found";
}else{
echo "Not Found";
}
> Found
Arrays: is_array()
• is_array — Finds whether a variable is an array
$arr = array("Kabul", "Balkh", "Herat",
"Qandahar");
if(is_array($arr)){
echo "YES";
}else{
echo "NO";
}
> YES
Arrays: shuffle()
• shuffle — Shuffle an array
$arr = array("Kabul", "Balkh", "Herat",
"Qandahar");
shuffle($arr);
print_r($arr);
> Array ( [0] => Balkh [1] => Herat [2] =>
Qandahar [3] => Kabul )
> Array ( [0] => Herat [1] => Qandahar [2]
=> Kabul [3] => Balkh )
> ….
Arrays: array_unique()
• array_unique — Removes duplicate values
from an array
$arr = array("Kabul", "Balkh", "Herat",
"Qandahar","Kabul");
$new_arr = array_unique($arr);
print_r($new_arr);
> Array ( [0] => Kabul [1] => Balkh [2] =>
Herat [3] => Qandahar )
LOOPS
• In computer programming, a loop is a sequence
of instructions that is continually repeated until a
certain condition is reached.
• An infinite loop is one that lacks a functioning exit
routine . The result is that the loop repeats
continually until the operating system senses it
and terminates the program with an error or until
some other event occurs (such as having the
program automatically terminate after a certain
duration of time).
LOOPS
• for – Syntax
• foreach - Syntax
for (init; condition; increment)
{
code to be executed;
}
foreach ($array as $value)
{
code to be executed;
}
LOOPS
• while – Syntax
• do-while – Syntax
while (condition)
{
code to be executed;
}
do
{
code to be executed;
}
while (condition);
PHP Functions
• The real power of PHP comes from its
functions.
• In PHP, there are more than 700 built-in
functions.
• A function will be executed by a call to the
function.
• You may call a function from anywhere within
a page.
PHP Functions: Syntax
• PHP function guidelines:
– Give the function a name that reflects what the
function does
– The function name can start with a letter or
underscore (not a number)
function functionName()
{
code to be executed;
}
PHP Functions: Sample
<html>
<body>
<?php
function writeName()
{
echo “Ahmad Mohammad Salih";
}
echo "My name is ";
writeName();
?>
</body>
</html>
PHP Functions - Adding parameters
• To add more functionality to a function, we
can add parameters. A parameter is just like a
variable.
• Parameters are specified after the function
name, inside the parentheses.
PHP Functions – Sample 2
<html>
<body>
<?php
function writeName($fname)
{
echo $fname . " Ahmadi.<br>";
}
echo "My name is ";
writeName(“Ahmad");
echo "My sister's name is ";
writeName(“Saliha");
echo "My brother's name is ";
writeName(“Mohammad");
?>
</body>
</html>
PHP Functions - Return values
• To let a function return a value, use the return
statement.
<html>
<body>
<?php
function add($x,$y)
{
$total=$x+$y;
return $total;
}
echo "1 + 16 = " . add(1,16);
?>
</body>
</html>
POST & GET
• GET requests can be cached
• GET requests remain in the browser history
• GET requests can be bookmarked
• GET requests should never be used when dealing
with sensitive data
• GET requests have length restrictions
– 1,024 characters is a safe upper limit
• GET requests should be used only to retrieve data
POST & GET
• POST requests are never cached
• POST requests do not remain in the browser
history
• POST requests cannot be bookmarked
• POST requests have no restrictions on data
length
POST & GET
<form action=”” method=”get”>
<form action=”” method=”post”>
Difference between PHP4 & PHP5
• PHP4 was powered by Zend Engine 1.0, while
PHP5 was powered by Zend Engine II.
• PHP4 is more of a procedure language while
PHP5 is object oriented.
• In PHP5 one can declare a class as Abstract.
• PHP5 incorporates static methods and properties.
• PHP5 introduces a special function called
__autoload()
Difference between PHP4 & PHP5
• In PHP5, there are 3 levels of visibilities: Public,
private and protected.
• PHP5 introduced exceptions.
• In PHP4, everything was passed by value,
including objects. Whereas in PHP5, all objects
are passed by reference.
• PHP5 introduces interfaces. All the methods
defined in an interface must be public.
• PHP5 introduces new functions.
Difference between PHP4 & PHP5
• PHP5 introduces some new reserved
keywords.
• PHP5 includes additional OOP concepts than
php4, like access specifiers , inheritance etc.
• PHP5 includes reduced consumption of RAM.
• PHP5 introduces increased security against
exploitation of vulnerabilities in PHP scripts.
• PHP5 introduces easier programming through
new functions and extensions.
Difference between PHP4 & PHP5
• PHP5 introduces a brand new built-in SOAP
extension for interoperability with Web
Services.
• PHP5 introduces a new SimpleXML extension
for easily accessing and manipulating XML as
PHP objects.
Exercise!
• Write a program which reverse the order of
the given string
• Write a function which returns the sum of all
elements in a given integer array.
• Write a program which returns the middle
element of a given array
• Write a program which find the duplicates of a
given array and return both the duplicate
values and the new duplicate-free array.
Exercise!
• Find the biggest item of an integer array
(Without using any built-in function e.g.
max())
• Write a program that check if a given program
is palindrome or not
• Write a function which takes an array
(key=>value formatted) as a parameter and
outputs the keys and values in separate
columns of a table.Key value
Exercise!
• A factorial of any given integer, n, is the product
of all positive integers between 1 and n inclu-sive.
So the factorial of 4 is 1 × 2 × 3 × 4 = 24, and the
factorial of 5 is 1 × 2 × 3 × 4 × 5 = 120. This can be
expressed recursively as follows:
– If n == 0, return 1. (This is the base case)
– If n > 0, compute the factorial of n–1, multiply it by n,
and return the result
Write a PHP script that uses a recursive function to
display the factorials of a given number.
QUESTIONS?

Mais conteúdo relacionado

Mais procurados

Practical approach to perl day1
Practical approach to perl day1Practical approach to perl day1
Practical approach to perl day1Rakesh Mukundan
 
Anonymous Functions in PHP 5.3 - Matthew Weier O’Phinney
Anonymous Functions in PHP 5.3 - Matthew Weier O’PhinneyAnonymous Functions in PHP 5.3 - Matthew Weier O’Phinney
Anonymous Functions in PHP 5.3 - Matthew Weier O’PhinneyHipot Studio
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP FunctionsAhmed Swilam
 
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
 
New SPL Features in PHP 5.3
New SPL Features in PHP 5.3New SPL Features in PHP 5.3
New SPL Features in PHP 5.3Matthew Turland
 
Programming in Computational Biology
Programming in Computational BiologyProgramming in Computational Biology
Programming in Computational BiologyAtreyiB
 
PHP applications/environments monitoring: APM & Pinba
PHP applications/environments monitoring: APM & PinbaPHP applications/environments monitoring: APM & Pinba
PHP applications/environments monitoring: APM & PinbaPatrick Allaert
 
Functional Programming with JavaScript
Functional Programming with JavaScriptFunctional Programming with JavaScript
Functional Programming with JavaScriptAung Baw
 
What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3Jeremy Coates
 
Building Data Mapper PHP5
Building Data Mapper PHP5Building Data Mapper PHP5
Building Data Mapper PHP5Vance Lucas
 
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
 
Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHPAhmed Swilam
 

Mais procurados (19)

Practical approach to perl day1
Practical approach to perl day1Practical approach to perl day1
Practical approach to perl day1
 
Anonymous Functions in PHP 5.3 - Matthew Weier O’Phinney
Anonymous Functions in PHP 5.3 - Matthew Weier O’PhinneyAnonymous Functions in PHP 5.3 - Matthew Weier O’Phinney
Anonymous Functions in PHP 5.3 - Matthew Weier O’Phinney
 
Groovy unleashed
Groovy unleashed Groovy unleashed
Groovy unleashed
 
Introduction to Perl and BioPerl
Introduction to Perl and BioPerlIntroduction to Perl and BioPerl
Introduction to Perl and BioPerl
 
Intro to Perl and Bioperl
Intro to Perl and BioperlIntro to Perl and Bioperl
Intro to Perl and Bioperl
 
Functions in php
Functions in phpFunctions in php
Functions in php
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
 
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
 
New SPL Features in PHP 5.3
New SPL Features in PHP 5.3New SPL Features in PHP 5.3
New SPL Features in PHP 5.3
 
Programming in Computational Biology
Programming in Computational BiologyProgramming in Computational Biology
Programming in Computational Biology
 
PHP applications/environments monitoring: APM & Pinba
PHP applications/environments monitoring: APM & PinbaPHP applications/environments monitoring: APM & Pinba
PHP applications/environments monitoring: APM & Pinba
 
Functional Programming with JavaScript
Functional Programming with JavaScriptFunctional Programming with JavaScript
Functional Programming with JavaScript
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3
 
Building Data Mapper PHP5
Building Data Mapper PHP5Building Data Mapper PHP5
Building Data Mapper PHP5
 
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
 
Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHP
 

Semelhante a Php Intermediate

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
 
Hsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdfHsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdfAAFREEN SHAIKH
 
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
 
Php basic for vit university
Php basic for vit universityPhp basic for vit university
Php basic for vit universityMandakini Kumari
 
PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackUAnshu Prateek
 
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 mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...anshkhurana01
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redisjimbojsb
 
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
 

Semelhante a Php Intermediate (20)

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
 
php
phpphp
php
 
Hsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdfHsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdf
 
05php
05php05php
05php
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
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)
 
Php basic for vit university
Php basic for vit universityPhp basic for vit university
Php basic for vit university
 
PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackU
 
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 classes in mumbai
Php classes in mumbaiPhp classes in mumbai
Php classes in mumbai
 
Php Basics
Php BasicsPhp Basics
Php Basics
 
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
 
Training on php by cyber security infotech (csi)
Training on  php by cyber security infotech (csi)Training on  php by cyber security infotech (csi)
Training on php by cyber security infotech (csi)
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
Initializing arrays
Initializing arraysInitializing arrays
Initializing arrays
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redis
 
Php
PhpPhp
Php
 
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)
 

Mais de Jamshid Hashimi

Week 2: Getting Your Hands Dirty – Part 2
Week 2: Getting Your Hands Dirty – Part 2Week 2: Getting Your Hands Dirty – Part 2
Week 2: Getting Your Hands Dirty – Part 2Jamshid Hashimi
 
Week 1: Getting Your Hands Dirty - Part 1
Week 1: Getting Your Hands Dirty - Part 1Week 1: Getting Your Hands Dirty - Part 1
Week 1: Getting Your Hands Dirty - Part 1Jamshid Hashimi
 
Introduction to C# - Week 0
Introduction to C# - Week 0Introduction to C# - Week 0
Introduction to C# - Week 0Jamshid Hashimi
 
RIST - Research Institute for Science and Technology
RIST - Research Institute for Science and TechnologyRIST - Research Institute for Science and Technology
RIST - Research Institute for Science and TechnologyJamshid Hashimi
 
How Coding Can Make Your Life Better
How Coding Can Make Your Life BetterHow Coding Can Make Your Life Better
How Coding Can Make Your Life BetterJamshid Hashimi
 
Tips for Writing Better Code
Tips for Writing Better CodeTips for Writing Better Code
Tips for Writing Better CodeJamshid Hashimi
 
Launch Your Local Blog & Social Media Integration
Launch Your Local Blog & Social Media IntegrationLaunch Your Local Blog & Social Media Integration
Launch Your Local Blog & Social Media IntegrationJamshid Hashimi
 
Introduction to Blogging
Introduction to BloggingIntroduction to Blogging
Introduction to BloggingJamshid Hashimi
 
Introduction to Wordpress
Introduction to WordpressIntroduction to Wordpress
Introduction to WordpressJamshid Hashimi
 
CodeIgniter Helper Functions
CodeIgniter Helper FunctionsCodeIgniter Helper Functions
CodeIgniter Helper FunctionsJamshid Hashimi
 
CodeIgniter Class Reference
CodeIgniter Class ReferenceCodeIgniter Class Reference
CodeIgniter Class ReferenceJamshid Hashimi
 
Managing Applications in CodeIgniter
Managing Applications in CodeIgniterManaging Applications in CodeIgniter
Managing Applications in CodeIgniterJamshid Hashimi
 
PHP Frameworks & Introduction to CodeIgniter
PHP Frameworks & Introduction to CodeIgniterPHP Frameworks & Introduction to CodeIgniter
PHP Frameworks & Introduction to CodeIgniterJamshid Hashimi
 

Mais de Jamshid Hashimi (20)

Week 2: Getting Your Hands Dirty – Part 2
Week 2: Getting Your Hands Dirty – Part 2Week 2: Getting Your Hands Dirty – Part 2
Week 2: Getting Your Hands Dirty – Part 2
 
Week 1: Getting Your Hands Dirty - Part 1
Week 1: Getting Your Hands Dirty - Part 1Week 1: Getting Your Hands Dirty - Part 1
Week 1: Getting Your Hands Dirty - Part 1
 
Introduction to C# - Week 0
Introduction to C# - Week 0Introduction to C# - Week 0
Introduction to C# - Week 0
 
RIST - Research Institute for Science and Technology
RIST - Research Institute for Science and TechnologyRIST - Research Institute for Science and Technology
RIST - Research Institute for Science and Technology
 
How Coding Can Make Your Life Better
How Coding Can Make Your Life BetterHow Coding Can Make Your Life Better
How Coding Can Make Your Life Better
 
Mobile Vision
Mobile VisionMobile Vision
Mobile Vision
 
Tips for Writing Better Code
Tips for Writing Better CodeTips for Writing Better Code
Tips for Writing Better Code
 
Launch Your Local Blog & Social Media Integration
Launch Your Local Blog & Social Media IntegrationLaunch Your Local Blog & Social Media Integration
Launch Your Local Blog & Social Media Integration
 
Customizing Your Blog 2
Customizing Your Blog 2Customizing Your Blog 2
Customizing Your Blog 2
 
Customizing Your Blog 1
Customizing Your Blog 1Customizing Your Blog 1
Customizing Your Blog 1
 
Introduction to Blogging
Introduction to BloggingIntroduction to Blogging
Introduction to Blogging
 
Introduction to Wordpress
Introduction to WordpressIntroduction to Wordpress
Introduction to Wordpress
 
CodeIgniter Helper Functions
CodeIgniter Helper FunctionsCodeIgniter Helper Functions
CodeIgniter Helper Functions
 
CodeIgniter Class Reference
CodeIgniter Class ReferenceCodeIgniter Class Reference
CodeIgniter Class Reference
 
Managing Applications in CodeIgniter
Managing Applications in CodeIgniterManaging Applications in CodeIgniter
Managing Applications in CodeIgniter
 
CodeIgniter Practice
CodeIgniter PracticeCodeIgniter Practice
CodeIgniter Practice
 
CodeIgniter & MVC
CodeIgniter & MVCCodeIgniter & MVC
CodeIgniter & MVC
 
PHP Frameworks & Introduction to CodeIgniter
PHP Frameworks & Introduction to CodeIgniterPHP Frameworks & Introduction to CodeIgniter
PHP Frameworks & Introduction to CodeIgniter
 
Exception & Database
Exception & DatabaseException & Database
Exception & Database
 
MySQL Record Operations
MySQL Record OperationsMySQL Record Operations
MySQL Record Operations
 

Último

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

Php Intermediate

  • 1. PHP Intermediate Jamshid Hashimi Trainer, Cresco Solution http://www.jamshidhashimi.com jamshid@netlinks.af @jamshidhashimi ajamshidhashimi Afghanistan Workforce Development Program
  • 2. Agenda • Arrays • Loop – For statement – Foreach statement – While statement – Do While statement • PHP Functions • Get & Post Variable • Difference between PHP 4 & PHP 5 • Exercise!
  • 3. Arrays • An array is a special variable, which can hold more than one value at a time. • array — Create an array • Multidimensional Arrays $arr = array("a" => "orange", "b" => "banana", "c" => "apple"); $fruits = array ( "fruits" => array("a" => "orange", "b" => " banana", "c" => "apple"), "numbers" => array(1, 2, 3, 4, 5, 6), "holes" => array("first", 5 => "second", " third") );
  • 4. Arrays: count() • count — Count all elements in an array, or something in an object $arr = array("Kabul", "Balkh", "Herat", "Qandahar"); echo count($arr); > 4
  • 5. Arrays: array_slice() • array_slice — Extract a slice of the array $arr = array("Kabul", "Balkh", "Herat", "Qandahar"); $new_arr = array_slice($arr,1,2); print_r($new_arr); > Array ( [0] => Balkh [1] => Herat )
  • 6. Arrays: array_reverse() • array_reverse — Return an array with elements in reverse order $arr = array("Kabul", "Balkh", "Herat", "Qandahar"); $new_arr = array_reverse($arr); print_r($new_arr); > Array ( [0] => Qandahar [1] => Herat [2] => Balkh [3] => Kabul )
  • 7. Arrays: array_keys() • array_keys — Return all the keys or a subset of the keys of an array $arr = array("Kabul", "Balkh", "Herat", "Qandahar"); $new_arr = array_keys($arr); print_r($new_arr); > Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 )
  • 8. Arrays: in_array() • in_array — Checks if a value exists in an array $arr = array("Kabul", "Balkh", "Herat", "Qandahar"); if(in_array("Kabul",$arr)){ echo "Found"; }else{ echo "Not Found"; } > Found
  • 9. Arrays: is_array() • is_array — Finds whether a variable is an array $arr = array("Kabul", "Balkh", "Herat", "Qandahar"); if(is_array($arr)){ echo "YES"; }else{ echo "NO"; } > YES
  • 10. Arrays: shuffle() • shuffle — Shuffle an array $arr = array("Kabul", "Balkh", "Herat", "Qandahar"); shuffle($arr); print_r($arr); > Array ( [0] => Balkh [1] => Herat [2] => Qandahar [3] => Kabul ) > Array ( [0] => Herat [1] => Qandahar [2] => Kabul [3] => Balkh ) > ….
  • 11. Arrays: array_unique() • array_unique — Removes duplicate values from an array $arr = array("Kabul", "Balkh", "Herat", "Qandahar","Kabul"); $new_arr = array_unique($arr); print_r($new_arr); > Array ( [0] => Kabul [1] => Balkh [2] => Herat [3] => Qandahar )
  • 12. LOOPS • In computer programming, a loop is a sequence of instructions that is continually repeated until a certain condition is reached. • An infinite loop is one that lacks a functioning exit routine . The result is that the loop repeats continually until the operating system senses it and terminates the program with an error or until some other event occurs (such as having the program automatically terminate after a certain duration of time).
  • 13. LOOPS • for – Syntax • foreach - Syntax for (init; condition; increment) { code to be executed; } foreach ($array as $value) { code to be executed; }
  • 14. LOOPS • while – Syntax • do-while – Syntax while (condition) { code to be executed; } do { code to be executed; } while (condition);
  • 15. PHP Functions • The real power of PHP comes from its functions. • In PHP, there are more than 700 built-in functions. • A function will be executed by a call to the function. • You may call a function from anywhere within a page.
  • 16. PHP Functions: Syntax • PHP function guidelines: – Give the function a name that reflects what the function does – The function name can start with a letter or underscore (not a number) function functionName() { code to be executed; }
  • 17. PHP Functions: Sample <html> <body> <?php function writeName() { echo “Ahmad Mohammad Salih"; } echo "My name is "; writeName(); ?> </body> </html>
  • 18. PHP Functions - Adding parameters • To add more functionality to a function, we can add parameters. A parameter is just like a variable. • Parameters are specified after the function name, inside the parentheses.
  • 19. PHP Functions – Sample 2 <html> <body> <?php function writeName($fname) { echo $fname . " Ahmadi.<br>"; } echo "My name is "; writeName(“Ahmad"); echo "My sister's name is "; writeName(“Saliha"); echo "My brother's name is "; writeName(“Mohammad"); ?> </body> </html>
  • 20. PHP Functions - Return values • To let a function return a value, use the return statement. <html> <body> <?php function add($x,$y) { $total=$x+$y; return $total; } echo "1 + 16 = " . add(1,16); ?> </body> </html>
  • 21. POST & GET • GET requests can be cached • GET requests remain in the browser history • GET requests can be bookmarked • GET requests should never be used when dealing with sensitive data • GET requests have length restrictions – 1,024 characters is a safe upper limit • GET requests should be used only to retrieve data
  • 22. POST & GET • POST requests are never cached • POST requests do not remain in the browser history • POST requests cannot be bookmarked • POST requests have no restrictions on data length
  • 23. POST & GET <form action=”” method=”get”> <form action=”” method=”post”>
  • 24. Difference between PHP4 & PHP5 • PHP4 was powered by Zend Engine 1.0, while PHP5 was powered by Zend Engine II. • PHP4 is more of a procedure language while PHP5 is object oriented. • In PHP5 one can declare a class as Abstract. • PHP5 incorporates static methods and properties. • PHP5 introduces a special function called __autoload()
  • 25. Difference between PHP4 & PHP5 • In PHP5, there are 3 levels of visibilities: Public, private and protected. • PHP5 introduced exceptions. • In PHP4, everything was passed by value, including objects. Whereas in PHP5, all objects are passed by reference. • PHP5 introduces interfaces. All the methods defined in an interface must be public. • PHP5 introduces new functions.
  • 26. Difference between PHP4 & PHP5 • PHP5 introduces some new reserved keywords. • PHP5 includes additional OOP concepts than php4, like access specifiers , inheritance etc. • PHP5 includes reduced consumption of RAM. • PHP5 introduces increased security against exploitation of vulnerabilities in PHP scripts. • PHP5 introduces easier programming through new functions and extensions.
  • 27. Difference between PHP4 & PHP5 • PHP5 introduces a brand new built-in SOAP extension for interoperability with Web Services. • PHP5 introduces a new SimpleXML extension for easily accessing and manipulating XML as PHP objects.
  • 28. Exercise! • Write a program which reverse the order of the given string • Write a function which returns the sum of all elements in a given integer array. • Write a program which returns the middle element of a given array • Write a program which find the duplicates of a given array and return both the duplicate values and the new duplicate-free array.
  • 29. Exercise! • Find the biggest item of an integer array (Without using any built-in function e.g. max()) • Write a program that check if a given program is palindrome or not • Write a function which takes an array (key=>value formatted) as a parameter and outputs the keys and values in separate columns of a table.Key value
  • 30. Exercise! • A factorial of any given integer, n, is the product of all positive integers between 1 and n inclu-sive. So the factorial of 4 is 1 × 2 × 3 × 4 = 24, and the factorial of 5 is 1 × 2 × 3 × 4 × 5 = 120. This can be expressed recursively as follows: – If n == 0, return 1. (This is the base case) – If n > 0, compute the factorial of n–1, multiply it by n, and return the result Write a PHP script that uses a recursive function to display the factorials of a given number.