29 EKİM 2009, PERŞEMBE
PHP Statik Değişkenler
$count = 5;
function get_count()
{
static $count = 0;
return $count ;
}
echo $count;
$count;
echo get_count();
echo get_count();
5 0 1 çıkışları ve onu doğru tahmin ettim,ama daha iyi bir açıklama istiyorum?
CEVAP
29 EKİM 2009, PERŞEMBE
$count = 5; // "outer" count = 5
function get_count()
{
static $count = 0; // "inner" count = 0 only the first run
return $count ; // "inner" count 1
}
echo $count; // "outer" count is still 5
$count; // "outer" count is now 6 (but you never echoed it)
echo get_count(); // "inner" count is now 1 = 1 (0 before the echo)
echo get_count(); // "inner" count is now 1 = 2 (1 before the echo)
echo get_count(); // "inner" count is now 1 = 3 (2 before the echo)
Bu zihninizi temizler umarım.
Bunu Paylaş:
Nerede statik değişkenler saklı (C/C )...
PHP Statik Değişkenler...
Fonksiyon statik değişkenler güvenli i...
JavaScript statik değişkenler...
'statik değişkenler anlamı ne bir...