PHP 代表超文本處理器,被設計為用於開發 Web 應用程式的伺服器端腳本語言。 PHP 程式碼主要與 HTML 語法結合或嵌入,但它可以用於 Web 應用程式的任何模板系統或可用的 Web 框架。
有許多 PHP 命令可用於各種環境,特別是用於準備一個 Web 應用程式或使用 HTML 語法嵌入整個伺服器端程式碼庫,並且對於普通開發人員來說非常容易學習。下面提到了一些基本的 PHP 指令:
廣告 該類別中的熱門課程 PHP 開發人員 - 專業化 | 8 門課程系列 | 3次模擬測驗開始您的免費軟體開發課程
網頁開發、程式語言、軟體測試及其他
IF [SPECIFIC CONDITION]{ [CODE] }ELSE IF [SPECIFIC CONDITION 2]{ [CODE] }ELSE { [CODE] }
PHP 也使用 switch case,就像其他程式語言一樣,以避免多個「IF ELSE」的巢狀定義。考慮多種情況的切換情況,定義預設值是可選的。定義 switch case 的程式碼結構如下:
SWITCH($var){ CASE 'val 1' [CODE] Break; CASE 'val 2' [CODE] Break; CASE 'val 3' [CODE] Break; DEFAULT [CODE] }
WHILE [condition or expression]{ [CODE] }
For(exp 1, exp 2, exp 3){ [CODE] }
DO { [CODE] }WHILE (condition)
FOREACH ($arr_var as $val){ [CODE] }
還有其他幾個流行的 PHP 命令,它們也被 PHP 開發人員使用,它們不是非常基本的命令,但更多地與 PHP 配合使用。下面列出了一些中間 PHP 命令類型:
In PHP, INCLUDE is mainly using for appending define code in an external file with the current working file.
INCLUDE ('name of the external file')
Maximum business logic can be defined within this PHP function.
Function "name of the function" (argument1, argument2 …){ [CODE] Return "expected result"; }
Array is mainly holding multiple related information in a single variable. Three kinds of arrays PHP normally supported.
It is similar to the HTML form.
<form action="" name="" type="post">
However, some of the critical tasks often need to be performed by the users of the PHP command. These tasks also have some advanced commands to execute, such as storing the cookie value, redirecting the page to some relevant pages or connecting to the database. Those advance kind of PHP commands are below:
A cookie is mainly using storing some of the user type value in their own system so that it can come automatically for the same website.
setCiookie(ckname, ckvalue, ckexpire, ckpath, ckdomain, cksecure) >>> creating Cookie $_COOKIE['cookie name'] >>> get cookies value
Redirecting to a new page by below command:
Header("Location:'URL to redirect'");
Some common users who are very frequently using PHP commands, they normally use some of the tips and tricks for utilizing PHP commands output in a proper way. Those kinds of tricks normally solving some user-specific queries and display execution output for understanding the same properly. Some of the very commonly used key tricks are:
For little critical complexity of business logic, sometimes developer using huge ‘IF-ELSE’ condition which creates a real problem of understanding the logic and final review. So one of the popular operators in PHP for avoiding the same is the Ternary operator. It is something like if conditions are true then doing something, else fetching some default value.
$value = (!empty($_GET['val'])? $_GET['val']: 'ABC');
Somehow requirement of using some common files in multiple pages, In that case rather than mention those common files in every page, a developer can make one common header and mention those common classes on that header page.
PHP is now a very popular programming language which used by the maximum common web application. If an organization are not a big concern with the site security or code vulnerability then PHP will be always a good option. The population of a page in PHP is very fast rather than any programming language.
以上是PHP指令的詳細內容。更多資訊請關注PHP中文網其他相關文章!