SlideShare una empresa de Scribd logo
1 de 30
Descargar para leer sin conexión
hasen@microcis.net July 03, 2013Hassen poreya
Trainer, Cresco Solution
Afghanistan Workforce
Development Program
PHP
Hypertext Pre-Processor
PHP
 PHP is a recursive acronym that stands for:
 PHP: Hypertext Preprocessor
 Hypertext :
 PHP is used to generate HTML pages.
 Preprocessor:
 The PHP code is processed before delivering HTML
content to the user.
PHP Tags
 Short tags
<?
?>
 Standard tags
<?php
?>
 XML compatible tags
<SCRIPT LANGUAGE="php">
</SCRIPT>
PHP Comments
 Single line comments
//this is a comment
#this is also a comment
 Multiple line comments
/*this is
a multiple line
comment
*/
A Simple PHP code
<html>
<head>
<title>My First PHP Script</title>
</head>
<body>
<?php
echo “Hello World!”;
?>
</body>
</html>
Language Basics – Semicolons
 Semicolons are used to separate different
statements.
<?php
echo “Hello World!”;
echo “Hi”;
?>
 Optional semicolons are coming after } but it’s
required to put a semicolon before }
if($day==“Monday”){
echo “Today is:”$day; //required semicolons here
}; //optional semicolons here
Language Basics – Variables Name
 Variables in PHP starts with $
 Case sensitive
$user_name and $User_Name (Different!!!)
 Valid variable names
$name
$day_of_month
$LastName
$_password
 Invalid variable names
$user name
$|
$5and10
Language Basics – Conventions
 Case sensitive
 Function names
 Class names
 Keywords
 You can not name your variables, functions, classes,
constants the same as a keyword.
 Constants -- Unchangeable value
 Does not start with $
 Using define()you can have a constant.
define(CONST', “A constant!");
echo CONST;
Data Types
 Scalar (Single value)
 Integers
 Floating-point numbers
 Boolean
 Strings
 Compound (Collections)
 Arrays
 Objects
 Special types
 Resource
 NULL
Integers
 Range [-2,147,483,648 to 2,147,483,647]
 Decimal
e.g. 2008
-123
 Octal numbers: a leading 0 and a sequence of digits
0-7
e.g. +0123
 Hexadecimal numbers: begin with 0x, followed by a
sequence of digits (0-9) or letters (A-F).
e.g. 0xFF
0x10
Floating-point Numbers
 Point (Decimal-point, floating-point)
 15 digits of accuracy
e.g.
0.61829384258
12.5
Testing a Data type
 is_int() or is_integer()
 Test, whether a value is an integer.
 is_float() or is_real()
 Test, whether a value is floating-point number.
 Return 1 if true, and 0 if false
<?php
$num=15;
$num2=4.5;
echo “$num is integer?”.is_int($num);
echo “<br> $num is float?”.is_float($num);
?>
Strings
 Strings are collections of textual data.
 e.g, “Microcis Software Solutions” or “Hello World!”
 Double quote VS single quote
 Double quotes expand the variables.
 Single quotes does not.
<?php
$a=“microcis”;
$b=„software‟;
$single=„single quote: $a‟;
double=“double quote: $b”
echo $single.“<br>”;
echo $double.“<br>”;
?>
NULL
 The special NULL value represents that a variable
has no value!
<?php
$var=NULL;
echo “$var is Null?”.is_null($var);
?>
 Use is_null() function whether a variable is
NULL.
Boolean
 A Boolean can be either TRUE or FALSE.
 The following values are considered FALSE
 The boolean(FALSE);
 The integer 0
 The float 0.0
 The empty string or string “0”
 The special type NULL
 An array with no elements
 An object with no value or functions
Boolean
 Every other value is considered as TRUE.
 -1 is considered TRUE, like any other non-zero number.
 Use is_bool() function to test whether a value
return true or false.
 Note: “something” is a string, not boolean; but it is
considered as boolean true.
Arrays
Arrays
 Array is series of objects which all have the same size
and type.
 Each object in an array is called an array element.
 A group of values
<?php
$city[0]=“Herat”;
$city[1]=“Kabul”;
$city[2]=“Mazar”;
?>
 You can also create an array using array()
$color=array(“Red”, “Green”, “Blue”);
print “$city[0] is $color[1]”;
Types of Arrays
 Associative arrays
 Numeric arrays
 Multidimensional arrays
Numeric Arrays
 A numeric array stores each element with a
numeric ID key.
$names = array(“Ahmad",“Mahmood",“Bob");
 In this example the ID key is automatically
assigned.
Associative Arrays
 With Associative arrays we can use strings as keys
and assign values to them.
$ages = array(“Ahmad"=>32, “Mahmood"=>30,
“Bob"=>34);
print_r($ages);
Multidimensional Arrays
 Each element in the main array can be an array.
And each element in the sub-array can also be an
array, and so on.
$countries = array(
“Afghanistan"=>array(“Herat",
“Kabul", “Mazar"), “Iran"=>array (
“Tehran" ), “Pakistan"=>array (
“Islamabad", “Peshavor", “Kerachi"
) );
Array Functions
print_r() function
 You can see the structure and values of any array
by using print_r() function.
print_r($fruit_basket);
 Output:
Array
(
[red] => apple
[orange] => orange
[yellow] => banana
[green] => pear
)
array_rand() function
 Returns a random key from an array, or it returns an
array of random keys.
 If you specify that, the function should return more
than one key.
array_rand(array,number);
<?php
$name=array("a"=>“Ahmad","b"=>“Bah
ram",“s"=>“Sina");
print_r(array_rand($name,1));
?>
 The output of the code above could be: b
Shuffle() function
 The shuffle() function randomizes the order
of the elements in the array.
shuffle(array);
<?php
$colors = array(“r" => “red", "b"
=> “blue", “g" => “green");
shuffle($colors);
print_r($colors);
?>
Output: Array ( [0] => blue [1] => green [2] => red )
str_split() function
 Splits a string into an array.
str_split(string,length)
 Parameters
 String: Specifies the string to split
 Length: Optional and specifies the length of each array
element. Default is 1
<?php
print_r(str_split("Hello"));
?>
str_split() function
 The output of the code above will be:
Array
(
[0] => H
[1] => e
[2] => l
[3] => l
[4] => o
)
Let’s codesomething
hasen@microcis.net July 03, 2013Hassen poreya
Trainer, Cresco Solution
Any Questions!

Más contenido relacionado

La actualidad más candente

PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisIan Macali
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requireTheCreativedev Blog
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & ArraysHenry Osborne
 
Learn PHP Basics
Learn PHP Basics Learn PHP Basics
Learn PHP Basics McSoftsis
 
Class 8 - Database Programming
Class 8 - Database ProgrammingClass 8 - Database Programming
Class 8 - Database ProgrammingAhmed Swilam
 
Introduction to PHP Lecture 1
Introduction to PHP Lecture 1Introduction to PHP Lecture 1
Introduction to PHP Lecture 1Ajay Khatri
 
Dev traning 2016 basics of PHP
Dev traning 2016   basics of PHPDev traning 2016   basics of PHP
Dev traning 2016 basics of PHPSacheen Dhanjie
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)Ajay Khatri
 
Php using variables-operators
Php using variables-operatorsPhp using variables-operators
Php using variables-operatorsKhem Puthea
 
Chap1introppt2php(finally done)
Chap1introppt2php(finally done)Chap1introppt2php(finally done)
Chap1introppt2php(finally done)monikadeshmane
 
Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9isadorta
 

La actualidad más candente (20)

PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and require
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
 
Learn PHP Basics
Learn PHP Basics Learn PHP Basics
Learn PHP Basics
 
php basics
php basicsphp basics
php basics
 
Class 8 - Database Programming
Class 8 - Database ProgrammingClass 8 - Database Programming
Class 8 - Database Programming
 
Introduction to PHP Lecture 1
Introduction to PHP Lecture 1Introduction to PHP Lecture 1
Introduction to PHP Lecture 1
 
Dev traning 2016 basics of PHP
Dev traning 2016   basics of PHPDev traning 2016   basics of PHP
Dev traning 2016 basics of PHP
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)
 
PHP MySQL
PHP MySQLPHP MySQL
PHP MySQL
 
Php using variables-operators
Php using variables-operatorsPhp using variables-operators
Php using variables-operators
 
Chap1introppt2php(finally done)
Chap1introppt2php(finally done)Chap1introppt2php(finally done)
Chap1introppt2php(finally done)
 
Php variables (english)
Php variables (english)Php variables (english)
Php variables (english)
 
Php introduction
Php introductionPhp introduction
Php introduction
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
Php Security
Php SecurityPhp Security
Php Security
 
Php & my sql
Php & my sqlPhp & my sql
Php & my sql
 
Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9
 

Destacado

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_07
Web app development_php_07Web app development_php_07
Web app development_php_07Hassen 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_php_05
Web app development_php_05Web app development_php_05
Web app development_php_05Hassen 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_crud_13
Web app development_crud_13Web app development_crud_13
Web app development_crud_13Hassen 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_11
Web app development_database_design_11Web app development_database_design_11
Web app development_database_design_11Hassen 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
 
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_php_06
Web app development_php_06Web app development_php_06
Web app development_php_06Hassen 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
 
Web app development_html_02
Web app development_html_02Web app development_html_02
Web app development_html_02Hassen Poreya
 

Destacado (15)

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_07
Web app development_php_07Web app development_php_07
Web app development_php_07
 
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_php_05
Web app development_php_05Web app development_php_05
Web app development_php_05
 
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_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_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_11
Web app development_database_design_11Web app development_database_design_11
Web app development_database_design_11
 
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
 
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_php_06
Web app development_php_06Web app development_php_06
Web app development_php_06
 
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
 
Web app development_html_02
Web app development_html_02Web app development_html_02
Web app development_html_02
 

Similar a Web app development_php_04

Similar a Web app development_php_04 (20)

PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
FYBSC IT Web Programming Unit IV PHP and MySQL
FYBSC IT Web Programming Unit IV  PHP and MySQLFYBSC IT Web Programming Unit IV  PHP and MySQL
FYBSC IT Web Programming Unit IV PHP and MySQL
 
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)
 
PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array. PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array.
 
php&mysql with Ethical Hacking
php&mysql with Ethical Hackingphp&mysql with Ethical Hacking
php&mysql with Ethical Hacking
 
unit 1.pptx
unit 1.pptxunit 1.pptx
unit 1.pptx
 
Php
PhpPhp
Php
 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
 
Php by shivitomer
Php by shivitomerPhp by shivitomer
Php by shivitomer
 
Php 101 by David Menendez
Php 101 by David MenendezPhp 101 by David Menendez
Php 101 by David Menendez
 
PHP
PHPPHP
PHP
 
PHP - Web Development
PHP - Web DevelopmentPHP - Web Development
PHP - Web Development
 
PHP and MySQL with snapshots
 PHP and MySQL with snapshots PHP and MySQL with snapshots
PHP and MySQL with snapshots
 
lab4_php
lab4_phplab4_php
lab4_php
 
lab4_php
lab4_phplab4_php
lab4_php
 
Php basic for vit university
Php basic for vit universityPhp basic for vit university
Php basic for vit university
 
Php
PhpPhp
Php
 
Web 8 | Introduction to PHP
Web 8 | Introduction to PHPWeb 8 | Introduction to PHP
Web 8 | Introduction to PHP
 
Php
PhpPhp
Php
 
Php basics
Php basicsPhp basics
Php basics
 

Último

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 

Último (20)

DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 

Web app development_php_04

  • 1. hasen@microcis.net July 03, 2013Hassen poreya Trainer, Cresco Solution Afghanistan Workforce Development Program PHP Hypertext Pre-Processor
  • 2. PHP  PHP is a recursive acronym that stands for:  PHP: Hypertext Preprocessor  Hypertext :  PHP is used to generate HTML pages.  Preprocessor:  The PHP code is processed before delivering HTML content to the user.
  • 3. PHP Tags  Short tags <? ?>  Standard tags <?php ?>  XML compatible tags <SCRIPT LANGUAGE="php"> </SCRIPT>
  • 4. PHP Comments  Single line comments //this is a comment #this is also a comment  Multiple line comments /*this is a multiple line comment */
  • 5. A Simple PHP code <html> <head> <title>My First PHP Script</title> </head> <body> <?php echo “Hello World!”; ?> </body> </html>
  • 6. Language Basics – Semicolons  Semicolons are used to separate different statements. <?php echo “Hello World!”; echo “Hi”; ?>  Optional semicolons are coming after } but it’s required to put a semicolon before } if($day==“Monday”){ echo “Today is:”$day; //required semicolons here }; //optional semicolons here
  • 7. Language Basics – Variables Name  Variables in PHP starts with $  Case sensitive $user_name and $User_Name (Different!!!)  Valid variable names $name $day_of_month $LastName $_password  Invalid variable names $user name $| $5and10
  • 8. Language Basics – Conventions  Case sensitive  Function names  Class names  Keywords  You can not name your variables, functions, classes, constants the same as a keyword.  Constants -- Unchangeable value  Does not start with $  Using define()you can have a constant. define(CONST', “A constant!"); echo CONST;
  • 9. Data Types  Scalar (Single value)  Integers  Floating-point numbers  Boolean  Strings  Compound (Collections)  Arrays  Objects  Special types  Resource  NULL
  • 10. Integers  Range [-2,147,483,648 to 2,147,483,647]  Decimal e.g. 2008 -123  Octal numbers: a leading 0 and a sequence of digits 0-7 e.g. +0123  Hexadecimal numbers: begin with 0x, followed by a sequence of digits (0-9) or letters (A-F). e.g. 0xFF 0x10
  • 11. Floating-point Numbers  Point (Decimal-point, floating-point)  15 digits of accuracy e.g. 0.61829384258 12.5
  • 12. Testing a Data type  is_int() or is_integer()  Test, whether a value is an integer.  is_float() or is_real()  Test, whether a value is floating-point number.  Return 1 if true, and 0 if false <?php $num=15; $num2=4.5; echo “$num is integer?”.is_int($num); echo “<br> $num is float?”.is_float($num); ?>
  • 13. Strings  Strings are collections of textual data.  e.g, “Microcis Software Solutions” or “Hello World!”  Double quote VS single quote  Double quotes expand the variables.  Single quotes does not. <?php $a=“microcis”; $b=„software‟; $single=„single quote: $a‟; double=“double quote: $b” echo $single.“<br>”; echo $double.“<br>”; ?>
  • 14. NULL  The special NULL value represents that a variable has no value! <?php $var=NULL; echo “$var is Null?”.is_null($var); ?>  Use is_null() function whether a variable is NULL.
  • 15. Boolean  A Boolean can be either TRUE or FALSE.  The following values are considered FALSE  The boolean(FALSE);  The integer 0  The float 0.0  The empty string or string “0”  The special type NULL  An array with no elements  An object with no value or functions
  • 16. Boolean  Every other value is considered as TRUE.  -1 is considered TRUE, like any other non-zero number.  Use is_bool() function to test whether a value return true or false.  Note: “something” is a string, not boolean; but it is considered as boolean true.
  • 18. Arrays  Array is series of objects which all have the same size and type.  Each object in an array is called an array element.  A group of values <?php $city[0]=“Herat”; $city[1]=“Kabul”; $city[2]=“Mazar”; ?>  You can also create an array using array() $color=array(“Red”, “Green”, “Blue”); print “$city[0] is $color[1]”;
  • 19. Types of Arrays  Associative arrays  Numeric arrays  Multidimensional arrays
  • 20. Numeric Arrays  A numeric array stores each element with a numeric ID key. $names = array(“Ahmad",“Mahmood",“Bob");  In this example the ID key is automatically assigned.
  • 21. Associative Arrays  With Associative arrays we can use strings as keys and assign values to them. $ages = array(“Ahmad"=>32, “Mahmood"=>30, “Bob"=>34); print_r($ages);
  • 22. Multidimensional Arrays  Each element in the main array can be an array. And each element in the sub-array can also be an array, and so on. $countries = array( “Afghanistan"=>array(“Herat", “Kabul", “Mazar"), “Iran"=>array ( “Tehran" ), “Pakistan"=>array ( “Islamabad", “Peshavor", “Kerachi" ) );
  • 24. print_r() function  You can see the structure and values of any array by using print_r() function. print_r($fruit_basket);  Output: Array ( [red] => apple [orange] => orange [yellow] => banana [green] => pear )
  • 25. array_rand() function  Returns a random key from an array, or it returns an array of random keys.  If you specify that, the function should return more than one key. array_rand(array,number); <?php $name=array("a"=>“Ahmad","b"=>“Bah ram",“s"=>“Sina"); print_r(array_rand($name,1)); ?>  The output of the code above could be: b
  • 26. Shuffle() function  The shuffle() function randomizes the order of the elements in the array. shuffle(array); <?php $colors = array(“r" => “red", "b" => “blue", “g" => “green"); shuffle($colors); print_r($colors); ?> Output: Array ( [0] => blue [1] => green [2] => red )
  • 27. str_split() function  Splits a string into an array. str_split(string,length)  Parameters  String: Specifies the string to split  Length: Optional and specifies the length of each array element. Default is 1 <?php print_r(str_split("Hello")); ?>
  • 28. str_split() function  The output of the code above will be: Array ( [0] => H [1] => e [2] => l [3] => l [4] => o )
  • 30. hasen@microcis.net July 03, 2013Hassen poreya Trainer, Cresco Solution Any Questions!