SlideShare una empresa de Scribd logo
1 de 20
Descargar para leer sin conexión
hasen@microcis.net July 09, 2013Hassen poreya
Trainer, Cresco Solution
Afghanistan Workforce
Development Program
PHP
Loops, Functions in PHP
for Loop
 A short and simple form of looping.
<?php
$colors= array('Black', 'Red', 'Green');
for($i = 0; $i < count($colors); $i++) {
$value = $colors[$i];
echo "$value<br>";
}
for($i=0; $i<=10; $i++){
echo $i;
}
?>
for Loop – Class exercise
 Output sum of 1 to 10.
 Write a for loop that outputs numbers from 1 by 5
up to 100.
 Try this out.
 Output the following using a for loop
*
**
***
****
*****
The date(); function
 PHP has a built-in function for creating date and
formats.
 The date(); function allows you to output
different date formats.
<?php
echo date('F j, Y'); // January 26, 2005
echo date('H:i'); // 23:14
echo date('Today is D'); // Today is Mon
?>
The date(); formats
The date(); formats
The date(); function – Class exercise
 Make your own date format and try to output this:
Today is
Tuesday, 8th of July 2013, 07:50:20 AM
The date(); function – Class exercise 2
 Write a piece of code that takes your birth date
(year) as input, and output your age!
Functions
Functions
 A block of code for specific tasks.
 Save compile time –only compile once.
 Reuse many times when needed.
 Optimize your code.
Functions
 Built-in functions like print(); date();
 User-defined functions:
 Function names cannot have spaces.
 Function name must begin with letter or underscore.
 E.g., call a built-in function abs();
<?php
$num=-5;
$new_num=abs($num);
echo $new_num;
?>
Declaring a Function
function function_name(arguments){
block of codes and statements;
}
 You can declare a function below a call to it.
 May have none, one, or multiple arguments each
separated by a comma.
 Write function name followed by ( ), even if the
function doesn’t have any arguments.
Example
<?php
function print_br($str) {
print "$str <br>";
}
print_br("line1");
print_br("line2");
?>
 Write a function to print a bold text.
 Write a function that outputs average between
three numbers.
Functions – Return Value
 Functions may have a return value.
 A return value in a function, returns the value to
the function that may be used later on while
calling a function.
 You may need to access the value that the function
returns, but you may not need to print it out,
that’s why you use a return value for a function.
Functions – Return Value
<?php
function multiply_by_two($value){
$result=$value*2;
return $result;
}
echo multiply_by_two(7);
?>
Functions – Without Return Value
<?php
function multiply_by_two($value){
$result=$value*2;
echo $result;
}
multiply_by_two(7);
?>
Exercise
 Write a function that outputs the square of a
number.
 Write a function that takes two arguments (Text,
and size) and then output a custom text with a
customer size.
 Use html <font size=‘x’>…</font>
PHP Built-in Functions
PHP built-in Functions
 Sqrt(); -- Take the square root of a number
 Ceil(); -- Take ceil of a decimal number
 Floor(); -- take the floor of a decimal number
 Max(); -- take the max number
 Min(); -- take the min number
 Strtolower(); -- convert string to lower case
 Strtoupper(); -- convert string to upper case
 …
 Do an example of each function by yourself.
hasen@microcis.net July 09, 2013Hassen poreya
Trainer, Cresco Solution
Any Questions!

Más contenido relacionado

La actualidad más candente

اسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونی
اسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونیاسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونی
اسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونی
Mohammad Reza Kamalifard
 

La actualidad más candente (20)

C programming function
C  programming functionC  programming function
C programming function
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
Lecture#6 functions in c++
Lecture#6 functions in c++Lecture#6 functions in c++
Lecture#6 functions in c++
 
CHAPTER 6
CHAPTER 6CHAPTER 6
CHAPTER 6
 
lets play with "c"..!!! :):)
lets play with "c"..!!! :):)lets play with "c"..!!! :):)
lets play with "c"..!!! :):)
 
Function overloading(C++)
Function overloading(C++)Function overloading(C++)
Function overloading(C++)
 
PHPLinq
PHPLinqPHPLinq
PHPLinq
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
Introduction to F# for the C# developer
Introduction to F# for the C# developerIntroduction to F# for the C# developer
Introduction to F# for the C# developer
 
03 function overloading
03 function overloading03 function overloading
03 function overloading
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Functions in PHP
Functions in PHPFunctions in PHP
Functions in PHP
 
Advance python programming
Advance python programming Advance python programming
Advance python programming
 
اسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونی
اسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونیاسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونی
اسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونی
 
Learning C++ - Functions in C++ 3
Learning C++ - Functions  in C++ 3Learning C++ - Functions  in C++ 3
Learning C++ - Functions in C++ 3
 
functions of C++
functions of C++functions of C++
functions of C++
 
Thinking in Functions: Functional Programming in Python
Thinking in Functions: Functional Programming in PythonThinking in Functions: Functional Programming in Python
Thinking in Functions: Functional Programming in Python
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Presention programming
Presention programmingPresention programming
Presention programming
 
function in c
function in cfunction in c
function in c
 

Destacado (15)

Web app development_php_04
Web app development_php_04Web app development_php_04
Web app development_php_04
 
Learn to Code with JavaScript - Choose Your Own Adventures
Learn to Code with JavaScript - Choose Your Own AdventuresLearn to Code with JavaScript - Choose Your Own Adventures
Learn to Code with JavaScript - Choose Your Own Adventures
 
Web app development_database_design_11
Web app development_database_design_11Web app development_database_design_11
Web app development_database_design_11
 
Web app development_my_sql_09
Web app development_my_sql_09Web app development_my_sql_09
Web app development_my_sql_09
 
Web app development_database_design_10
Web app development_database_design_10Web app development_database_design_10
Web app development_database_design_10
 
Web app development_database_design_er-mapping_12
Web app development_database_design_er-mapping_12Web app development_database_design_er-mapping_12
Web app development_database_design_er-mapping_12
 
Web app development_php_07
Web app development_php_07Web app development_php_07
Web app development_php_07
 
Web app development_my_sql_08
Web app development_my_sql_08Web app development_my_sql_08
Web app development_my_sql_08
 
Web app development_html_css_03
Web app development_html_css_03Web app development_html_css_03
Web app development_html_css_03
 
Web app development_php_05
Web app development_php_05Web app development_php_05
Web app development_php_05
 
Web app development_crud_13
Web app development_crud_13Web app development_crud_13
Web app development_crud_13
 
CodeIgniter Practice
CodeIgniter PracticeCodeIgniter Practice
CodeIgniter Practice
 
Web app development_html_02
Web app development_html_02Web app development_html_02
Web app development_html_02
 
Web app development_cookies_sessions_14
Web app development_cookies_sessions_14Web app development_cookies_sessions_14
Web app development_cookies_sessions_14
 
Web app development_html_01
Web app development_html_01Web app development_html_01
Web app development_html_01
 

Similar a Web app development_php_06

Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
mussawir20
 
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
Kumar
 

Similar a Web app development_php_06 (20)

Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
 
Web Technology_10.ppt
Web Technology_10.pptWeb Technology_10.ppt
Web Technology_10.ppt
 
Drupaljam xl 2019 presentation multilingualism makes better programmers
Drupaljam xl 2019 presentation   multilingualism makes better programmersDrupaljam xl 2019 presentation   multilingualism makes better programmers
Drupaljam xl 2019 presentation multilingualism makes better programmers
 
Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample Questions
 
lab4_php
lab4_phplab4_php
lab4_php
 
lab4_php
lab4_phplab4_php
lab4_php
 
php user defined functions
php user defined functionsphp user defined functions
php user defined 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 FUNCTIONS AND ARRAY.pptx
PHP FUNCTIONS AND ARRAY.pptxPHP FUNCTIONS AND ARRAY.pptx
PHP FUNCTIONS AND ARRAY.pptx
 
PHP PPT FILE
PHP PPT FILEPHP PPT FILE
PHP PPT FILE
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
 
CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love Affair
 
Php
PhpPhp
Php
 
Incredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and GeneratorsIncredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and Generators
 
PHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesPHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return Types
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
Python basic
Python basicPython basic
Python basic
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!
 
slidesharenew1
slidesharenew1slidesharenew1
slidesharenew1
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 

Web app development_php_06

  • 1. hasen@microcis.net July 09, 2013Hassen poreya Trainer, Cresco Solution Afghanistan Workforce Development Program PHP Loops, Functions in PHP
  • 2. for Loop  A short and simple form of looping. <?php $colors= array('Black', 'Red', 'Green'); for($i = 0; $i < count($colors); $i++) { $value = $colors[$i]; echo "$value<br>"; } for($i=0; $i<=10; $i++){ echo $i; } ?>
  • 3. for Loop – Class exercise  Output sum of 1 to 10.  Write a for loop that outputs numbers from 1 by 5 up to 100.  Try this out.  Output the following using a for loop * ** *** **** *****
  • 4. The date(); function  PHP has a built-in function for creating date and formats.  The date(); function allows you to output different date formats. <?php echo date('F j, Y'); // January 26, 2005 echo date('H:i'); // 23:14 echo date('Today is D'); // Today is Mon ?>
  • 7. The date(); function – Class exercise  Make your own date format and try to output this: Today is Tuesday, 8th of July 2013, 07:50:20 AM
  • 8. The date(); function – Class exercise 2  Write a piece of code that takes your birth date (year) as input, and output your age!
  • 10. Functions  A block of code for specific tasks.  Save compile time –only compile once.  Reuse many times when needed.  Optimize your code.
  • 11. Functions  Built-in functions like print(); date();  User-defined functions:  Function names cannot have spaces.  Function name must begin with letter or underscore.  E.g., call a built-in function abs(); <?php $num=-5; $new_num=abs($num); echo $new_num; ?>
  • 12. Declaring a Function function function_name(arguments){ block of codes and statements; }  You can declare a function below a call to it.  May have none, one, or multiple arguments each separated by a comma.  Write function name followed by ( ), even if the function doesn’t have any arguments.
  • 13. Example <?php function print_br($str) { print "$str <br>"; } print_br("line1"); print_br("line2"); ?>  Write a function to print a bold text.  Write a function that outputs average between three numbers.
  • 14. Functions – Return Value  Functions may have a return value.  A return value in a function, returns the value to the function that may be used later on while calling a function.  You may need to access the value that the function returns, but you may not need to print it out, that’s why you use a return value for a function.
  • 15. Functions – Return Value <?php function multiply_by_two($value){ $result=$value*2; return $result; } echo multiply_by_two(7); ?>
  • 16. Functions – Without Return Value <?php function multiply_by_two($value){ $result=$value*2; echo $result; } multiply_by_two(7); ?>
  • 17. Exercise  Write a function that outputs the square of a number.  Write a function that takes two arguments (Text, and size) and then output a custom text with a customer size.  Use html <font size=‘x’>…</font>
  • 19. PHP built-in Functions  Sqrt(); -- Take the square root of a number  Ceil(); -- Take ceil of a decimal number  Floor(); -- take the floor of a decimal number  Max(); -- take the max number  Min(); -- take the min number  Strtolower(); -- convert string to lower case  Strtoupper(); -- convert string to upper case  …  Do an example of each function by yourself.
  • 20. hasen@microcis.net July 09, 2013Hassen poreya Trainer, Cresco Solution Any Questions!