首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 網頁程式設計 >> PHP 程式設計 >> PHP 相關知識

PHP 內建函數速查手冊(一):數學、Adabas D、Apache 與陣列核心函數

     編輯:PHP 相關知識

數學函數

函數說明範例
abs($num)絕對值,浮點數回傳 float,整數回傳 intabs(-3.14) → 3.14
acos($arg)反餘弦,回傳弧度acos(0) → 1.5708 (π/2)

Adabas D 資料庫擴充(冷門歷史擴充)

Adabas D 為早期嵌入式資料庫,PHP 4 時代內建支援,現代專案極少使用,僅作歷史參考。

Apache 專用函數(需 mod_php / Apache SAPI)

函數說明
ada_connect()連線資料源
ada_exec()準備並執行 SQL
ada_fetchrow()取得下一列
ada_fieldname()取得欄位名
ada_numrows()結果集列數
ada_close()關閉連線
函數說明
apache_lookup_uri($uri)執行部分子請求,回傳資源資訊物件
apache_note($name, $value?)讀寫請求筆記,模組間傳遞資料
getallheaders()取得所有 HTTP 請求標頭(關聯陣列)
virtual($filename)執行 Apache 子請求,輸出結果(可包含 CGI/.shtml)

getallheaders 範例

<?php
$headers = getallheaders();
foreach ($headers as $name => $value) {
    echo "$name: $value<br>";
}
?>

陣列核心函數

array() 建立陣列

<?php
$fruits = [
    'fruits'  => ['a' => 'orange', 'b' => 'banana', 'c' => 'apple'],
    'numbers' => [1, 2, 3, 4, 5, 6],
    'holes'   => ['first', 5 => 'second', 'third'], // 指定索引 5
];
?>

array_walk() 逐元素回呼

<?php
$fruits = ['d' => 'lemon', 'a' => 'orange', 'b' => 'banana', 'c' => 'apple'];

function testPrint($item) { echo "$item<br>"; }
function testAlter(&$item) { $item = 'bogus'; } // 參考修改

array_walk($fruits, 'testPrint');
array_walk($fruits, 'testAlter');
array_walk($fruits, 'testPrint'); // 全變 bogus
?>

arsort() 關聯陣列值降序排序(保留鍵)

<?php
$scores = ['Alice' => 85, 'Bob' => 92, 'Cindy' => 78];
arsort($scores);
// ['Bob'=>92, 'Alice'=>85, 'Cindy'=>78]
?>

下一期預告

將涵蓋字串處理(strlen, substr, strpos, sprintf)、檔案系統(fopen, file_get_contents, glob)、日期時間(date, strtotime, DateTime)等高頻函數族群。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved