2013年6月2日 星期日

isset(), empty() and is_null()

http://techtalk.virendrachandak.com/php-isset-vs-empty-vs-is_null/

大致上做個總結:
NULL是用來代表變數尚未被給值,或者變數還沒被配置記憶體

1. isset() - Determines if a variable is set(配置記憶體) and is not NULL
換句話說,只有變數是not null時isset()才會回傳true

2. empty() - Determines if a variable is empty
empty()在下面這些值時會回傳true:an empty string, false, array(), NULL, “0?, 0, and an unset variable

3. is_null() - Finds whether a variable is NULL
要注意,isset()可以被用在unknown variables上,但is_null只能被用在declared variables

題外話:unset()是用來把變數從記憶體中釋放

沒有留言:

張貼留言