<?php
class config {
public static function get($path = null) {
if ($path) {
$config = $GLOBALS['config'];
$path = explode('/', $path);
foreach($path as $bit) {
if (isset($config[$bit])) {
$config = $config[$bit];
}
}
return $config;
}
return false;
}
}
?>
我跟隨本教程http://www.youtube.com/watch?v=S6vDgLwJ7n8&list=PLfdtiltiRHWF5Rhuk7k4UAU1_yLAZzhWc來自phpacademy。我迷路了,不能理解這條線如何閱讀複雜變量?
function get ($path = null)
----這是什麼意思?根據我的理解,它說「得到$path
的價值」。但是這引出了另一個問題,我在哪裏可以得到$path
的價值?請啓發我,並用英文翻譯此聲明。
if ($path)
-----檢查$ path是否有值嗎?
$config = $config[$bit]
----這是我第一次遇到這個,我無法理解,因爲有一個括號中有一個變量。請賜教,教我如何翻譯這本書,並用純英文閱讀。
數組教程:http://oreilly.com/catalog/progphp/chapter/ch05.html –
參考:[php中的函數](http://www.php.net/manual/en/language.functions。 php) – Gordon
在附註中,您可能想要找到更好的教程,因爲您顯示的代碼存在一些問題,例如它訪問全局狀態和靜態,這很容易導致不可維護的應用程序充滿副作用和僵化,很難更改代碼。 – Gordon