| 函數 | 說明 |
ada_connect() | 連線資料源 |
ada_exec() | 準備並執行 SQL |
ada_fetchrow() | 取得下一列 |
ada_fieldname() | 取得欄位名 |
ada_numrows() | 結果集列數 |
ada_close() | 關閉連線 |
Apache 專用函數(需 mod_php / Apache SAPI)
| 函數 | 說明 |
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)等高頻函數族群。
- 上一篇文章: PHP 多維陣列遍歷與操作完全指南:foreach、array_walk、array_map 實戰
- 下一篇文章: PHP UBB 代碼解析器實作:Cls_Ubb 類別完整代碼與正則替換邏輯
Copyright ©
程式碼之家 All Rights Reserved