Characters are often used in programming languages or HTML in php
Identifier
is a name coined by the programmers to name variables, functions and classes.
Identifier Naming rules:
A. Starting with the letter or the underscore (_)
2. Subsequent characters can be letters, numbers, or underscore (_)
3. Are case sensistive,
4. Not use punctuation.
example:
• the name of
• nama_pengguna
• _nama
• kuartal13
• Username
Type of data
Data types are divided into 4 parts:
1. integer
state is the data type integer. Integer range depending on the platform, about 2 billion.
Integer can be expressed to decimal notation (base 10), hexadecimal (base 16) and octal (base 8).
The use of octal notation must begin with 0 (zero) while the use of hexadecimal notation preceded 0x
2. Doble
3. string
is a set of characters. In PHP a character is considered as a byte, so there are 256 different characters.
A string literal can dinyatakn in three different ways:
- A single quotation mark (single quote)
- Double quotation mark (double quote)
- Heredoc sintax
4. boolean
is the simplest type of data, ie to express a truth value TRUE (true) or FALSE (false), which is case sensitive.
example:
$ pass = TRUE;
Variables
dala is a computer memory location to store a value or data. The contents of a variable can change during the program.
Dealam PHP variables are always preceded by a $ sign, followed by variable names are case sensitive.
Examples of naming variables:
variable Specification
Price Unit One, because there are spaces
Wages / Day One, because there are signs /
4persegi One, because the leading
True _4persegi
True GajiTotal
True Nama_Tamu
Divided into three types:
A. Global variables
is a global variable that can be known and used by all parts of the script.
2. Local variables
is a variable that is defined in a function so that the variable can only be identified and used in the function of declaring variables.
3. Static variables
is a variable that exists only in the local scope of a function. Variable does not eliminate the value of the end when finished and leave the function is executed.
• Example script variabel
Nama file : variabel.php
$Nama = “Ray”;
$NAMA = “Rio”;
$nama = “Roy’;
echo “$Nama, $NAMA, $nama “;
?>
• Examples of single quotation marks string script
$tulisan = ‘Menggunakan PHP’;
echo ‘Ini adalah suatu string’.’,br>’;
echo ‘Anda bisa menyisipkan newlines dalam string, seperti ini.’.’
’;
echo ‘Arnold berkata: I\’ll be back’.’
’;
echo ‘are you sure you want to delete c:\\*.*? ‘.’
’;
echo ‘am trying to include at this point:\rn a newline’.’
’;
echo ‘$tulisan’.’
’;
?>
• Sample script string double quotes
$tulisan = “Menggunakan PHP”;
echo “Ini adalah suatu string”.”,br>”;
echo “Anda bisa menyisipkan newlines dalam string, seperti ini.”.”
”;
echo “Arnold berkata: I\’ll be back”.”
”;
echo “are you sure you want to delete c:\\*.*? “.”
”;
echo “am trying to include at this point:\rn a newline”.”
”;
echo “$tulisan”.”
”;
?>
• Sample script heredoc string sintax
Nama File : string3.php
Penggunaan heredoc sintax
$STRINGKU = <<
AKHIR;
echo <<
sintax
\$STRINGKU =$STRINGKU
KET;
?>
• Sample script boolean
Nama File : Boolean1.php
Contoh Nilai Boolean
$a = TRUE;
$b = false;
Hasil eksekusi dengan PHP :
Hasil eksekusi dengan PHP :
$a = TRUE;
$b = false;
echo “$a = $a”.”
”;
echo “$b = $b”;
?>
• Example of script integer
Nama File : integer.php
Tipe Data Integer
$Harga = 15000;
$Jumlah = 5;
$HargaTotal = $Harga * $Jumlah;
echo “Harga = $Harga”.”
”;
echo “Jumlah = $Jumlah”.”
”;
echo “Harga Total =
$HargaTotal”.”
”;
$large_number = 2147483647;
var_dump($large_number);
echo “
”;
$large_number = 2147483648;
var_dump($large_number);
echo “
”;
var_dump(80000000);
echo “
”;
$million = 1000000;
$large_number = 50000 * $million;
var_dump($large_number);
?>
0 comments:
Posting Komentar