$poll_userID、$auth_userRole$maxRetryCount 優於 $mrcPHP 是解釋型、弱類型語言:
int . string → string)<?php
$myStr = 789696; // 整數
$myVar = 2; // 整數
$myStr = "This is my favorite band: "; // 字符串
$myStr = $myStr . "U" . $myVar; // 自動轉換拼接
echo "$myVar\n"; // 輸出 2
?>
C/Java 中此代碼將拋出類型錯誤,PHP 無縫運行。
<?php
// config.ini
[database]
host = "localhost"
user = "root"
pass = "secret"
name = "myapp"
[app]
debug = true
version = "1.0.0"
// 解析器
function parseConfig($file) {
$ini = parse_ini_file($file, true); // 二維數組:section => key=>value
foreach ($ini as $section => $values) {
foreach ($values as $key => $value) {
// 可變變量名:${section}_{key} → $database_host, $app_debug
${$section . '_' . $key} = $value;
}
}
}
// 使用
parseConfig('config.ini');
echo $database_host; // localhost
echo $app_debug; // 1 (true)
?>