SlideShare une entreprise Scribd logo
1  sur  20
Télécharger pour lire hors ligne
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!

Contenu connexe

Tendances

C programming function
C  programming functionC  programming function
C programming functionargusacademy
 
Lecture#6 functions in c++
Lecture#6 functions in c++Lecture#6 functions in c++
Lecture#6 functions in c++NUST Stuff
 
Function overloading(C++)
Function overloading(C++)Function overloading(C++)
Function overloading(C++)Ritika Sharma
 
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# developernjpst8
 
Advance python programming
Advance python programming Advance python programming
Advance python programming Jagdish Chavan
 
اسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونی
اسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونیاسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونی
اسلاید دوم جلسه پنجم کلاس پایتون برای هکرهای قانونیMohammad Reza Kamalifard
 
Learning C++ - Functions in C++ 3
Learning C++ - Functions  in C++ 3Learning C++ - Functions  in C++ 3
Learning C++ - Functions in C++ 3Ali Aminian
 
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 PythonAnoop Thomas Mathew
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT03062679929
 
Presention programming
Presention programmingPresention programming
Presention programmingsaleha iqbal
 
function in c
function in cfunction in c
function in csubam3
 

Tendances (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
 

En vedette

Web app development_php_04
Web app development_php_04Web app development_php_04
Web app development_php_04Hassen Poreya
 
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 AdventuresTessa Mero
 
Web app development_database_design_11
Web app development_database_design_11Web app development_database_design_11
Web app development_database_design_11Hassen Poreya
 
Web app development_my_sql_09
Web app development_my_sql_09Web app development_my_sql_09
Web app development_my_sql_09Hassen Poreya
 
Web app development_database_design_10
Web app development_database_design_10Web app development_database_design_10
Web app development_database_design_10Hassen Poreya
 
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_12Hassen Poreya
 
Web app development_php_07
Web app development_php_07Web app development_php_07
Web app development_php_07Hassen Poreya
 
Web app development_my_sql_08
Web app development_my_sql_08Web app development_my_sql_08
Web app development_my_sql_08Hassen Poreya
 
Web app development_html_css_03
Web app development_html_css_03Web app development_html_css_03
Web app development_html_css_03Hassen Poreya
 
Web app development_php_05
Web app development_php_05Web app development_php_05
Web app development_php_05Hassen Poreya
 
Web app development_crud_13
Web app development_crud_13Web app development_crud_13
Web app development_crud_13Hassen Poreya
 
Web app development_html_02
Web app development_html_02Web app development_html_02
Web app development_html_02Hassen Poreya
 
Web app development_cookies_sessions_14
Web app development_cookies_sessions_14Web app development_cookies_sessions_14
Web app development_cookies_sessions_14Hassen Poreya
 
Web app development_html_01
Web app development_html_01Web app development_html_01
Web app development_html_01Hassen Poreya
 

En vedette (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
 

Similaire à 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 Functionsmussawir20
 
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 programmersAlexander Varwijk
 
Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsJagat Kothari
 
php user defined functions
php user defined functionsphp user defined functions
php user defined functionsvishnupriyapm4
 
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 FUNCTIONS AND ARRAY.pptx
PHP FUNCTIONS AND ARRAY.pptxPHP FUNCTIONS AND ARRAY.pptx
PHP FUNCTIONS AND ARRAY.pptxShaliniPrabakaran
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboardsDenis Ristic
 
CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairMark
 
Incredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and GeneratorsIncredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and Generatorsdantleech
 
PHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesPHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesEric Poe
 
Function in c program
Function in c programFunction in c program
Function in c programumesh patil
 

Similaire à 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
 

Dernier

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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...apidays
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
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 DevelopmentsTrustArc
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
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 slidevu2urc
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
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 productivityPrincipled Technologies
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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 MenDelhi Call girls
 

Dernier (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
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
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
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
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
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
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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
 

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!