Kata kunci ialah perkataan yang mempunyai beberapa makna. Dalam penggunaan biasa bahasa PHP, perkataan ini tidak boleh digunakan sebagai pemalar, nama pembolehubah, nama kaedah, nama kelas, dll. Kata kunci ini apabila digunakan secara automatik difahami oleh PHP. Kata kunci PHP ini, apabila digunakan dengan nama pembolehubah, boleh dikelirukan dengan kata kunci sebenar. Oleh itu, kata kunci ini tidak boleh digunakan sebagai nama pembolehubah.
IKLAN Kursus Popular dalam kategori ini PEMBANGUN PHP - Pengkhususan | 8 Siri Kursus | 3 Ujian Olok-olokMulakan Kursus Pembangunan Perisian Percuma Anda
Pembangunan web, bahasa pengaturcaraan, ujian perisian & lain-lain
Berikut ialah senarai:
Kod:
'.$this->MethodOne(); } } class ProgramOne extends Program { protected function MethodOne() { echo '
'.'In MethodOne'; } } $objOne = new ProgramOne; $objOne->display(); ?>,
Output:
Kod :
Output:
Kod:
"east", "w" => "west", "n" => "north", "s" => "south"); print_r($directions); ?>
Output:
Kod:
"east", "w" => "west", "n" => "north", "s" => "south"); foreach($directions as $key=>$value) { echo '
'. $key. '=>'.$value; } ?>
Output:
Kod :
$value) { if($value == 'try') { break ; // can use break 1 also } echo '
'.$value; } ?>
Output:
Kod:
"."One"; break; case 2: echo "
"."Two"; break; case 3: echo "
"."Three"; break; default: echo "
"."Default"; } $i++; } ?>
Output:
Kod:
getMessage()); } } Operation(); ?>
Output:
Kod:
str; } } $obj = new ClassOne; $obj->displayMethod(); ?>
Output:
kata kunci const digunakan untuk mentakrifkan nama dengan nilai menggunakan operator tugasan seperti di bawah
UMUR konst= 29;
Tiada tanda $ pada permulaan nama tetap seperti pembolehubah biasa.
Kod:
Output :
Kod:
2) { echo 'x is greater than 2'; } else{ echo 'x is less than 2'; } } while ($x < 2); ?>
Output:
Kod :
Output:
Kod:
Output:
Kod:
5) { echo "a is greater than 10"; } else { echo "a is not greater than 10"; } ?>
Output:
Kod:
10) { echo "a is greater than 10"; } elseif ($a == 10) { echo "a is equal to 10"; } else { echo "a is smaller than 10"; } ?>
Output :
Kod:
Output:
Kod:
".$i; endfor; ?>
Output:
Kod :
10): echo "a is greater than 10"; elseif ($a >10) : echo "a is equal to 10"; else: echo "a is not equal to 10"; endif; ?>
Output:
Kod:
$value): echo '
'.$value; endforeach; ?>
Output:
Kod:
Output:
Kod:
".$i; $i++; endwhile; ?>
Output:
Code:
".$string; eval("\$string = \"$string\";"); echo "
".$string; ?>
Output:
This keyword when encountered in a script, terminates the execution of the script.
Code:
string; } } class ExtendClass extends ParentClass { public function display() { echo 'Hello World!'; } } $obj1 = new ExtendClass; $obj1->display(); ?>
Output:
Code:
string; } } class ExtendClass extends ParentClass { public function display() { echo 'Hello World!'; } } $obj1 = new ExtendClass; $obj1->display(); ?>
Output :
Code:
'.$e->getMessage(); } ?>
Output:
Code:
'.$i; } ?>
Output :
Code:
'.$value/10; } ?>
Output:
Code:
The sum : '.$result; ?>
Output:
Code:
Output:
Code:
Output:
Code:
first(); ?>
Output :
Code:
file.php
index.php
Code:
file.php
index.php
Output:
Code:
Output:
Code:
This is the one function'; } public function two() { echo '
This is the two function'; } } $obj = new MainClass; echo $obj->one(); echo $obj->two(); ?>
Output:
Code:
Output :
Code:
Output:
Code:
score('Sunil','Maths',90); ?>
Output:
Code:
Output :
Code:
"."Hello $stringOne $stringTwo"; ?>
Output :
Code:
str. ' Method'; } } $obj = new MainClass(); $obj->PrivateMethod(); //Shows Private Method ?>
Output:
Code:
str. ' Method'; } } $obj = new MainClass(); $obj->PublicMethod(); //Shows Public Method ?>
Output:
Code:
str. ' Method'; } } $obj = new MainClass(); $obj->ProtectedMethod(); //Shows Protected Method ?>
Output:
Code:
Output:
Code:
"."One"; break; case 2: echo "
"."Two"; break; case 3: echo "
"."Three"; break; default: echo "
"."Default"; } ?>
Output:
Code:
'.$e->getMessage(); } } division(10,0); ?>
Output:
Code:
'.$e->getMessage(); } ?>
Output:
Code:
'; $a = 10; echo $a; unset($a); // echo $a; //this line when uncommented shows error : Undefined variable, as the variable is unset ?>
Output:
Code:
str; } } $obj = new MainClass; $obj->displayMsg(); ?>
Output:
Code:
'. $i; $i++; } ?>
Output:
In this article, you will learn about keywords in PHP with examples. These examples explain the usage of each of the keyword in PHP.
Atas ialah kandungan terperinci Kata Kunci PHP. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!