SlideShare a Scribd company logo
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!

More Related Content

PDF
Data Types In PHP
PDF
03phpbldgblock
PPT
PHP - Introduction to PHP
PDF
Sorting arrays in PHP
PDF
Introduction to php
PPT
PHP variables
PPTX
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
PDF
PHP-Part1
Data Types In PHP
03phpbldgblock
PHP - Introduction to PHP
Sorting arrays in PHP
Introduction to php
PHP variables
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
PHP-Part1

What's hot (20)

PPTX
PHP Powerpoint -- Teach PHP with this
PPT
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PPTX
PHP Functions & Arrays
PPTX
Learn PHP Basics
PPTX
php basics
PPTX
Class 8 - Database Programming
PPTX
Introduction to PHP Lecture 1
PPTX
Dev traning 2016 basics of PHP
PPTX
PHP Basics
PPTX
Basics of Java Script (JS)
PPT
PPSX
Php using variables-operators
PPTX
Chap1introppt2php(finally done)
ODP
Php variables (english)
PPTX
Php introduction
ODP
PHP Web Programming
PDF
Php Security
PPTX
Php & my sql
PPT
Open Source Package Php Mysql 1228203701094763 9
PHP Powerpoint -- Teach PHP with this
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP Functions & Arrays
Learn PHP Basics
php basics
Class 8 - Database Programming
Introduction to PHP Lecture 1
Dev traning 2016 basics of PHP
PHP Basics
Basics of Java Script (JS)
Php using variables-operators
Chap1introppt2php(finally done)
Php variables (english)
Php introduction
PHP Web Programming
Php Security
Php & my sql
Open Source Package Php Mysql 1228203701094763 9
Ad

Viewers also liked (15)

PDF
Web app development_html_css_03
PDF
Web app development_php_07
PDF
Web app development_database_design_10
PDF
Web app development_php_05
PDF
Web app development_my_sql_08
PDF
Web app development_crud_13
PPTX
CodeIgniter Practice
PDF
Web app development_my_sql_09
PDF
Web app development_database_design_11
PDF
Web app development_database_design_er-mapping_12
PPTX
Learn to Code with JavaScript - Choose Your Own Adventures
PDF
Web app development_php_06
PDF
Web app development_cookies_sessions_14
PDF
Web app development_html_01
PDF
Web app development_html_02
Web app development_html_css_03
Web app development_php_07
Web app development_database_design_10
Web app development_php_05
Web app development_my_sql_08
Web app development_crud_13
CodeIgniter Practice
Web app development_my_sql_09
Web app development_database_design_11
Web app development_database_design_er-mapping_12
Learn to Code with JavaScript - Choose Your Own Adventures
Web app development_php_06
Web app development_cookies_sessions_14
Web app development_html_01
Web app development_html_02
Ad

Similar to Web app development_php_04 (20)

PPT
Php my sql - functions - arrays - tutorial - programmerblog.net
PPTX
PHP Basics
PPTX
Ch1(introduction to php)
PPT
Web Technology_10.ppt
PPT
PHP and MySQL with snapshots
PPTX
Php intro by sami kz
PPTX
PHPneweeeeeeeeeeeeeeeeeeeeeeeeeeeeee.pptx
PPTX
Lecture4 php by okello erick
PPTX
PPTX
Php by shivitomer
PPTX
Introduction To PHP000000000000000000000000000000.pptx
PPT
Php basics
PPT
Php course-in-navimumbai
PDF
Web 8 | Introduction to PHP
PPTX
Introduction to PHP_ Lexical structure_Array_Function_String
PPTX
Php basics
PPSX
DIWE - Advanced PHP Concepts
PDF
Hsc IT 5. Server-Side Scripting (PHP).pdf
PPTX
Chapter 4 server side Php Haypertext P.pptx
Php my sql - functions - arrays - tutorial - programmerblog.net
PHP Basics
Ch1(introduction to php)
Web Technology_10.ppt
PHP and MySQL with snapshots
Php intro by sami kz
PHPneweeeeeeeeeeeeeeeeeeeeeeeeeeeeee.pptx
Lecture4 php by okello erick
Php by shivitomer
Introduction To PHP000000000000000000000000000000.pptx
Php basics
Php course-in-navimumbai
Web 8 | Introduction to PHP
Introduction to PHP_ Lexical structure_Array_Function_String
Php basics
DIWE - Advanced PHP Concepts
Hsc IT 5. Server-Side Scripting (PHP).pdf
Chapter 4 server side Php Haypertext P.pptx

Recently uploaded (20)

PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Empathic Computing: Creating Shared Understanding
PPTX
1. Introduction to Computer Programming.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Encapsulation theory and applications.pdf
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
A Presentation on Artificial Intelligence
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Assigned Numbers - 2025 - Bluetooth® Document
Unlocking AI with Model Context Protocol (MCP)
Per capita expenditure prediction using model stacking based on satellite ima...
Empathic Computing: Creating Shared Understanding
1. Introduction to Computer Programming.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Advanced methodologies resolving dimensionality complications for autism neur...
Encapsulation_ Review paper, used for researhc scholars
A comparative analysis of optical character recognition models for extracting...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Diabetes mellitus diagnosis method based random forest with bat algorithm
Mobile App Security Testing_ A Comprehensive Guide.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation theory and applications.pdf
gpt5_lecture_notes_comprehensive_20250812015547.pdf
cuic standard and advanced reporting.pdf
Big Data Technologies - Introduction.pptx
Network Security Unit 5.pdf for BCA BBA.
A Presentation on Artificial Intelligence
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf

Web app development_php_04

  • 1. [email protected] 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. [email protected] July 03, 2013Hassen poreya Trainer, Cresco Solution Any Questions!