0 оценок0% нашли этот документ полезным (0 голосов)
39 просмотров43 страницы
PHP l variable type 8 support v Booleans - > True / Falsev Floats -> 2.9,3.0v strings - > (,,", "", here documents (allows strings are multiple lines)v Arrays -> similar to dictionaries in Python and hashes in Perl (It provides key / value Pairs)v NULL - > Special Data Type (Reference to a third party resource)v resource -> Special Data Type
PHP l variable type 8 support v Booleans - > True / Falsev Floats -> 2.9,3.0v strings - > (,,", "", here documents (allows strings are multiple lines)v Arrays -> similar to dictionaries in Python and hashes in Perl (It provides key / value Pairs)v NULL - > Special Data Type (Reference to a third party resource)v resource -> Special Data Type
Авторское право:
Attribution Non-Commercial (BY-NC)
Доступные форматы
Скачайте в формате DOCX, PDF, TXT или читайте онлайн в Scribd
PHP l variable type 8 support v Booleans - > True / Falsev Floats -> 2.9,3.0v strings - > (,,", "", here documents (allows strings are multiple lines)v Arrays -> similar to dictionaries in Python and hashes in Perl (It provides key / value Pairs)v NULL - > Special Data Type (Reference to a third party resource)v resource -> Special Data Type
Авторское право:
Attribution Non-Commercial (BY-NC)
Доступные форматы
Скачайте в формате DOCX, PDF, TXT или читайте онлайн в Scribd
by Nulled Byte on Sunday, 25 September 2011 at 21:02
mmso.org php tutorial
PHP Learning Part 1 php tutorial l !T Field tag l deactivate tag l tag l
Chapter I (Introduction of PHP) PHP Personal Home Page l Pre Hypertext Processor (Hypertext Pre Processor) l PHP Dynamic Web Site l Server Side Scripting Language
PHP Tags PHP Tag +
Long Tag (or) Standard Tag
?>
Short Tag
?> Alternative Long Tags <script language=php></script> ASP Style Tag echo l Eg~ echo command print command
PHP Tag multiple statement statement ; Eg~ Chapter II (Comments) Comments PHP Coding Coding comment Page Browser
PHP comments 3 v C Style commentv C++ Style Commentsv Unix/Linux Style Com ments C Style Comments/**/ C Style Comments comments Nultiple Lines
Eg~ C++ Style Comments //
comment l // Eg~ Unix/Linux Style Comments#
comment l # Eg~ Chapter III (Variables) variable value l special container programming fundamental l
v Numbersv strings of charactersv objectsv Arraysv Booleans
hold l variable $ l
Types of Variables that PHP supports PHP l variable type 8 support v Booleans - > True/Falsev Integers -> (decimal, octal, hex)v Floats -> 2.9,3.0v Strings - > (, , here documents (allows strings are multiple lines))v Arrays -> similar to dictionaries in Python and hashes in Perl (It provides key/value Pairs)v Objectsv NULL - > Special Data Type (An uninitialized variable)v Resource -> Special Data Type (Reference to a third party resource) (Eg~ Database or etc..) Remark PHP Variables must be named with alphas and/or underscore
Eg~ $first_var = Data;$second_var = Data; variable value hold l special container ll value Cyber, Hunter, Student, 25 variable
value variable type l Cyber, Hunter, Student value hold variable $first_name, $last_name, $occupation variable strings 25 value hold $age variable integer l l integer $age variable 25 value strings value ' ', " " quote l variable echo variable l space l "\t" tab l coding ll Coding echo $first_name, \t, $last_na me, \t, $occupation, \t, $age; Space l "\t" " " Eg~ echo $first_name, " ", $last_name, " ", $occupation, " ", $age; $first_name variable l $last_name variable space 2 variable space l
" " value variable interpolation ' ' value non variable interpolation
Cyber Hunter is a Student 25 output echo $var1, "\t", $var2, "\t", $var3, "\n", $age; l Cyber Hunter is a Student 25 Browser echo $var1, '\t', $var2, '\t, $var3, '\t', $age; l Cyber\tHunter\tis a Student\n25 Browser Chapter IV (Basic for Strings) String PHP Script coding Browser Hello World. I am Cyber Hunter. I love PHP. l Chapter V (Basic of integers) integer PHP file string value l output l calculation script echo $num1; echo echo 10; l l $num1 variable l $num2 variable script ll $num1 variable l $num2 variable result browser variable l l 10 l 20 result browser $result v ariable $num1 l $num2 l $result variable result coding $num1 variable 10 $num2 variable 20 $num1 l $num2 l $result $result variable echo l 30 result l
multiply $num1 variable l hold 2 l $um2 variable l hold 3 l multiply l result browser value multiply value divide
coding num1 variable value 6 num2 variable value 3 l divide result browser
/ Arithmetic Operator 10/2 10 2 ll 5 l 5%2 l 1 result l l
E.g~ coding $num1 $num2 l l % Arithmetic Operator l Browser 1 l Arithmetic Operator
+++|Arithmetic Operators|+++ Operator Definition Example Result of Example
Eg~ SQL quries (SQL statements) here document php script
Eg~It's used to see multiple lines.Hopefully that you'll understand.cyberhunter;echo $va rhere1;?> script browser
This is the first line of here document. It's used to see multiple lines. Hopefully that you'll understand. here document cyberhunter l cyberhunter keyword l cyberhunter keyword l interpreter l variable hold value
cyberhunter keyword line l ll space here document standard syntax script l HTNL enter l
here document variable interpulation
here document PHP scripting language BASH, Perl, Python scripting language support
Booleans Boolean TruefFalse value condition True or False
Unix Shell 0 True Programming environment
boolean statement condition
Arrays Arrays variable type Arrays Perl l hashes l Python l dictionaries Arrays keyfvalue Pairs provide ( Perl l hashes l Python l dictionaries keyfvalue Pairs store ) variable value hold l special container variable value store Arrays multiple values variable store
Chapter VII (Operators & Exp ressions) Operators multiple value value l operator value l value operator l operate l value operand l
2+3 2 l 3 value operand l value l operate operator + Operators operand
coding l coding $var1 variable type l gettype() function browser $var1 variable type integer
Eg~ ff The following is the alternate way of the above code coding $meter variable 15000 value hold l kilometer 1 kilometer 1000 meters 15000 value 1000 l kilometer echo
assignment operator $x = 3; assignment operator l echo $x = x + 3; echo x variable l hold value l 3 value l browser l result 6
Eg~ coding $x = 3; value x operand assign echo $x + = 4; echo $x value ope rand value + l result l 7 l Combined Assignment Operator l v += $x += 5 $x = $x + 5v -= $x -= 5 $x = $x - 5v /= $x /= 5 $x = $x / 5v *= $x *= 5 $x = $x * 5v %= $x %= 5 $x = $x % 5v .= $x .= " test" $x = $x." test" Comparison Operators Comparison Operator statement condition loop statement condition l loop Comparison Operator statement condition l code block loop Definition Comparison Operators
v == Equivalence Left value is equivalent to right value v != Non-equivalence Left value isnt equivalent to right value v === Identical Left is equivalent to right and they are the same type v > Greater than Left is greater than right v Less than Left is less than right v >= Greater than or equal to Left is greater than or equal to right v Less than or equal to Left is less than or equal to right Chapter VIII (Constants) Constants variable value define variable value change l Eg~ coding $var1 value Cyber Hunter $var1 value Terminator $var1 value Terminator l constants l define() function l syntax define ("Syntax_Name", "value");
Eg~ coding var1 value Cyber Hunter var1 valu e Terminator define var1 l constant value Cyber Hunter l Terminator echo c onstant value Cyber Hunter browser Chapter IX (Switching Flow) PHP file output l PHP file dynamic l if statement ll if Statement if Statement l statement expression true value statement statement if statement syntax if (expression){/*code to execute if the statemen t is true*/} l Eg~ coding $user variable value Cyber Hunter $user Cyber Hunter value l This user is Cyber Hunter echo l condition statement condition $user variable value Cyber Hunter ll This user is Cyber Hunter Cyber Hunter l This user is Cyber Hunter output l else clause if statement l $user value Cyber Hunter This user is unknown user output
Eg~ coding $user value Cyber Hunter if Statement $user value user10 expression This user is Cyber Hunter statement expression This user is unknown user else l This user is unknown user else clause l statement
else if clause if else l expression else if l
else process l syntax
if(expression1){/*code to execute if the statement is true*/}el se if(expression2){/*code to execute if the previous statement is false and this stateme nt is true*/}else{/*code to execute none of the above statements are false*/} l Eg~ Switch Statement Switch Statement if Statement if Statement l Switch Statement l expression l case l l l l
Switch Statement l syntax
switch (expression) { case result1: // exec ute this if expression results in result1 break; case result2: // execute this if ex pression results in result2 break; default: // execute this if no break statement // has been encountered hitherto} l
Eg~ coding $cyberhunter value Site Admin Noderator, Global Noderator value l $cyberhunter l This member is in the Noderator Group echo value l v!P, Contributor case Banned, Spammer l Administrator, Site Admin, Board Admin l This member is in the Administrator Group l l Sorry, this user haven't registered yet break; statement
if Statement condition expression Switch Statement Nultiple condition expression l
? Operator (ternary Operator) ? Operator (ternary Operator) if Statement l l syntax
(expression) ?returned_if_expression_is_true:returned_if_expres sion_is_false; l
Eg~ coding $cyberhunter value Site Admin $user l $admin l value d efine $result ($cyberhunter=="Normal User") ex pression $cyberhunter value Site Admin expression $user return $admin return ($cy berhunter=="Normal User") $admin return $result echo $admin return This user is Site Admin browser Chapter X (Loops) Loop code execute
task repeat
loop statement while Statement l while Statement while Statement syntax if Statement l while Statement statement expression l code operate loop code block execution iteration l while Statement syntax while ( expression ){ // Code to execute} l Eg~ ";$number++;}?> coding $number = 1; integer $number $number 12 l 12 l $number*2 execute l $number++ $number 1 l iteration $number*2 1 2 l 2 echo statement $number++ $number value 1 1 2 12 loop iteration $number 1 2 $number*2 $number value 2 2 l + statement statement $number++ $number value 2 1 3 value 12 loop l $number 12 l loop result browser
Results :-
1 x 2 is 2 2 x 2 is 4 3 x 2 is 6 4 x 2 is 8 5 x 2 is 10 6 x 2 is 12 7 x 2 is 14 8 x 2 is 16 9 x 2 is 18 10 x 2 is 20 11 x 2 is 22 12 x 2 is 24
do while Loop do while Loop while loop l while loop l condition code execute while expression execute l syntax do { // code to be executed} while (expression ); l Eg~ \n";$num++;}while ( $num > 200 && $num coding $num = 1; integer do The value of the number is: $num $num echo while loop $num > 200 88 $num < +00 l $num 200 +00 condition $num 1 while loop condition The value of the number is: 1 browser l $num 201 201 399 browser do $num $num echo $num++ $num 1 while statement $num 202 condition $num 202 echo $num++ 202 1 203 203 while 200 +00 loop l 399 loop browser result
for statement while loop l while loop l for loop l data initialization condition testing modification expression l while loop value loop while l condition code block loop loop code block modification expression for loop process l code block loop l l syntax for ( initialization expression; test expression; modificatio n expression ){ // code to be executed} l
E.g~ ";}?> coding for l $number = 1; $number variable 1 value $number coding run browser
Results :-
1 x 2 is 2 2 x 2 is 4 3 x 2 is 6 4 x 2 is 8 5 x 2 is 10 6 x 2 is 12 7 x 2 is 14 8 x 2 is 16 9 x 2 is 18 10 x 2 is 20 11 x 2 is 22 12 x 2 is 24
Using the break Statement to end the loop break statement break statement loop l for (x = 1; x E.g~ ";)?> coding l for ($x = 1; $x
Using the continue Statement to skip the iteration break statement loop terminate continue statement loop
break looping terminate continue looping loop l continue l
E.g~ ";}?> coding for ($x = -5; $x "; 100 $x value l l $y value ll l 100 -5, -+, -3, -2, -1 l -1 l 0 100f0 error (mathematics 0 ll) error for loop if ($x == 0) { continue; ) 100 0 l iteration iteration state
Nesting 2 loopings iteration iteration l browser ll E.g~
I want as follows : 12345 12345 12345 12345 12345
coding ? looping looping coding E.g~ ";while ($x ";$x++;}?> coding x alphabet l l echo l l $x = 1; $x value 1 l while loop while ($x
while loop loopA l loopA while loop loopB l coding ll $x 1 loopA while ($x "; l br $x++; $x 1 2 2 loopA condition 5 loopA code block loopA code block $y = 1; while ($y Result:- I want as follows :
12345 12345 12345 12345 12345 coding for loop l syntax concept
coding $var1 value 1 1 integer $var1 data type echo gettype($var1); $var1 variable gettype() Iunction echo $var1 data type integer browser integer echo $var1; echo $var1 value 1
Eg~ Code: $var1 = -123; $var2 = abs( $var1 ); echo $var2; // it will show "123" ?>
$var1 = -123; $var2 variable value $var1 abs() function result $var2 assignment operator $var2 echo abs() Iunction process generate result 123 value browser -123 value hold $var1 abs() Iunction -123 data process coding
Eg~ Code: $var1 = -123; $var2 = abs( -123 ); echo "$var2, "; // it will show "123" echo gettype($var2), " ", gettype($var1); ?>
value variable assign Iunction coding coding
Eg~ Code: echo (abs(-123)); ?> built-in Iunction
user-deIined Iunction
User-defined functions Iunction syntax
Syntax :- Code: function function_name( $argument1, $argument2 ) { // code for function }
$var1 $var2 $result $result return calculator Iunction code block browser certain result Iunction data
material output certain result Iunction data echo calculator (1, 2); 1 value $var1 assign 2 value $var2 assign calculator Iunction code block $var1 value 1 $var2 value 2 value $result variable assign $result return step by step process certain output 3 value browser
return
return value process return result return $result $result value return $result $var1 $var2 $var1 Iunction 1 $var2 2 $var1 + $var2 $var1 1 $var2 2 3 result 3 result $result return $result $result return 3 output
$result return 5 value return browser 5 return 5; 5 value
$var1 = "This is variable1"; function function_one() { echo "Testing: $var1"; } function_one(); ?>
coding
Iunction declare variable Iunction
global statement coding
PHP Code:
$var1 = "Hello Word"; function function_one() { global $var1; echo "Greeting from the script : $var1"; } function_one(); ?>
coding $var1 value Hello World.! assign function_one() Iunction Iunctionone code block $var1 global $var1; global statement echo Iunction process process result Greeting from the script : Hello World.! browser programmer
global statement variable variable Iunction Iunction variable value $var1 1; Iunction global $var1; $var1; $var1 value $var1; $var1 value 1 1 $var1 value 2
coding PHP Code:
$var1 = 1; function function_one() { global $var1; $var1++; echo $var1, " "; } function_one(); function_one(); ?> coding $var1 =1;
$var1 = 1; function function_one ($var2) { global $var1; echo "$var1."." "."$var2", " "; $var1++; } function_one ("This is line 1"); function_one ("This is line 2"); function_one ("This is line 3"); ?>
static statement static variable value
global statement declare variable Iunction local variable
coding PHP Code:
$var1 = 1; function function_one ($var2) { static $var1 = 1; echo "$var1."." "."$var2", " "; $var1++; } function_one ("This is line 1"); function_one ("This is line 2"); function_one ("This is line 3"); ?> coding $var1 value 1 static $var1 = 0; $var1 0
coding PHP Code:
$var1 = 1; function function_one ($var2) { static $var1 = 0; echo "$var1."." "."$var2", " "; $var1++; } function_one ("This is line 0"); function_one ("This is line 1"); function_one ("This is line 2"); ?>
Test Bank For Intro To Python For Computer Science and Data Science Learning To Program With Ai Big Data and The Cloud by Paul J Deitel Harvey M Deitel