INTRODUCTION PHP
PHP is a scripting language that integrates with the HTML and run on the server side. This means that all the syntax that we provide will be fully executed on the server while the browser is sent to the result only.
File contoh1.php:
Simple Example
title>
head>
php
echo ( "Hallo apakabar? My name is PHP script");
?>
body>
html>
Variable
PHP in the name of each variable beginning dollar sign ($). For example the name of a variable in PHP is written with the $ a. Type of a variable is determined at the time of the road program and depending on the context used.
File contoh2.php:
php
$ a = "5";
$ b = "2";
$ result = $ a + $ b;
echo ($ result);
?>
STRUCTURE Control
IF
IF construction is used to perform the execution of a conditional statement.
How is written as follows:
if (condition)
(
statement
)
or:
if (condition)
(
statement
)
else
(
another statement
)
or:
if (first condition)
(
The first statement
)
elseif (both terms)
(
second statement
)
else
(
another statement
)
File contoh5.php:
php
$ a = 4;
$ b = 9;
if ($ a> $ b)
(
echo ( "a is greater than in b");
)
elseif ($ a <$ b)
(
echo ( "a small b");
)
else
(
echo ( "a with the b");
)
?>
While
Form the basis of the While statement is as follows:
while (condition)
(
statement
)
While the meaning of statemant is to give the command to execute the statement
underneath are repeated, during the condition fulfilled.
File contoh6.php:
php
$ a = 1;
while ($ a <10)
(
echo ($ a);
$ a + +;
)
?>
FOR
How to write FOR statement is as follows:
for (ekspresi1; ekspresi2; ekspresi3)
statement
ekspresi1 initial value for a variable
ekspresi2 shows the requirements that must be met to run statemant
ekspresi3 show value-added to a variable
File contoh7.php:
php
for ($ a = 0; $ a <10; $ a + +)
(
echo ( "A = value");
echo ( "$ a");
echo ( "
");
)
?>
SWITCH
SWITCH statement is used to compare a variable with some
value and the statement if the value of certain variables with the same value
compared.
Switch structure is as follows:
switch (variable)
case value:
statement
case value:
statemant
case value:
statement
.
.
.
File contoh8.php:
php
$ a = 2;
switch ($ a)
(
case 1:
echo ( "Value is a variable one");
break;
case 2:
echo ( "Value is a two-variable");
break;
case 3:
echo ( "Value is a three-variable");
break;
)
?>
Require
Require statement is used to read the variable value and function of a file. How to write Require statement is:
require (filename);
Require this statement can not be entered diadalam a looping structure such as while or for. Because only pemangggilan the same file only once.
File contoh9.php:
php
$ a = "I'm learning PHP";
tulistebal function ($ text)
(
echo ( " $ text b>");
)
?>
File contoh10.php:
php
require ( "contoh9.php");
tulistebal ( "This is a bold any posts");
echo ( "
");
echo ($ a);
?>
Include
Include statement will include the content of a particular file. Include can be put
eg in a looping in a for or while statement.
File contoh11.php:
php
echo ("-------------< br> ");
echo ( "PHP is a scripting language
");
echo ("-------------< br> ");
echo ( "
");
?>
File contoh12.php:
php
for ($ b = 1; $ b <5; $ b + +)
(
include ( "contoh11.php");
)
?>
PHP is a scripting language that integrates with the HTML and run on the server side. This means that all the syntax that we provide will be fully executed on the server while the browser is sent to the result only.
File contoh1.php:
Simple Example
title>
head>
php
echo ( "Hallo apakabar? My name is PHP script");
?>
body>
html>
Variable
PHP in the name of each variable beginning dollar sign ($). For example the name of a variable in PHP is written with the $ a. Type of a variable is determined at the time of the road program and depending on the context used.
File contoh2.php:
php
$ a = "5";
$ b = "2";
$ result = $ a + $ b;
echo ($ result);
?>
STRUCTURE Control
IF
IF construction is used to perform the execution of a conditional statement.
How is written as follows:
if (condition)
(
statement
)
or:
if (condition)
(
statement
)
else
(
another statement
)
or:
if (first condition)
(
The first statement
)
elseif (both terms)
(
second statement
)
else
(
another statement
)
File contoh5.php:
php
$ a = 4;
$ b = 9;
if ($ a> $ b)
(
echo ( "a is greater than in b");
)
elseif ($ a <$ b)
(
echo ( "a small b");
)
else
(
echo ( "a with the b");
)
?>
While
Form the basis of the While statement is as follows:
while (condition)
(
statement
)
While the meaning of statemant is to give the command to execute the statement
underneath are repeated, during the condition fulfilled.
File contoh6.php:
php
$ a = 1;
while ($ a <10)
(
echo ($ a);
$ a + +;
)
?>
FOR
How to write FOR statement is as follows:
for (ekspresi1; ekspresi2; ekspresi3)
statement
ekspresi1 initial value for a variable
ekspresi2 shows the requirements that must be met to run statemant
ekspresi3 show value-added to a variable
File contoh7.php:
php
for ($ a = 0; $ a <10; $ a + +)
(
echo ( "A = value");
echo ( "$ a");
echo ( "
");
)
?>
SWITCH
SWITCH statement is used to compare a variable with some
value and the statement if the value of certain variables with the same value
compared.
Switch structure is as follows:
switch (variable)
case value:
statement
case value:
statemant
case value:
statement
.
.
.
File contoh8.php:
php
$ a = 2;
switch ($ a)
(
case 1:
echo ( "Value is a variable one");
break;
case 2:
echo ( "Value is a two-variable");
break;
case 3:
echo ( "Value is a three-variable");
break;
)
?>
Require
Require statement is used to read the variable value and function of a file. How to write Require statement is:
require (filename);
Require this statement can not be entered diadalam a looping structure such as while or for. Because only pemangggilan the same file only once.
File contoh9.php:
php
$ a = "I'm learning PHP";
tulistebal function ($ text)
(
echo ( " $ text b>");
)
?>
File contoh10.php:
php
require ( "contoh9.php");
tulistebal ( "This is a bold any posts");
echo ( "
");
echo ($ a);
?>
Include
Include statement will include the content of a particular file. Include can be put
eg in a looping in a for or while statement.
File contoh11.php:
php
echo ("-------------< br> ");
echo ( "PHP is a scripting language
");
echo ("-------------< br> ");
echo ( "
");
?>
File contoh12.php:
php
for ($ b = 1; $ b <5; $ b + +)
(
include ( "contoh11.php");
)
?>
0 Comments:
Post a Comment