PHP değişkenlerinde aşağıdaki veri tiplerine ait değerler saklanmaktadır.
- “boolean“
- “integer“
- “double” (tarihsel sebeplerle float durumunda “double” döndürülür)
- “string“
- “array“
- “object“
- “resource“
- “NULL“
- “unknown type”
boolean
1 2 3 4 5 6 7 8 9 | <?php $durum=true; if($durum==true) echo "durum true olarak işaretlenmiş"; ?> |
integer
1 2 3 4 5 6 7 8 9 | <?php $x = 5; $y = 4; $sonuc= $x + $y; echo $sonuc; ?> |
double
1 2 3 4 5 6 7 8 9 10 11 | <?php $ucret=15.75; $kdv=1.18; $toplam=$ucret*$kdv; echo $toplam; ?> |
string
1 2 3 4 5 6 7 8 9 | <?php $isim="merhaba dünya"; echo $isim; ?> |
array
1 2 3 4 5 6 7 | <?php $dizi=[20,"merhaba",true,12.70]; print_r($dizi); |
object
1 2 3 4 5 6 7 8 9 10 11 12 13 | <?php class Kisi{ public $ad; public $soyad; function adSoyadGetir(){ return $this->ad." ".$this->soyad; } } $kisi1=new Kisi(); |
Özel kaynaklar tarafından oluşturulan ham veriler için kullanılır. Örn. ftp bağlantısından gelen dosyalar, grafik kütüphanesi ile oluşturulan resim belgesi vs.
1 2 3 4 5 6 7 8 9 10 11 12 | <?php header("Content-Type: image/png"); $im = @imagecreate(500, 100) or die("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($im, 255, 255, 0); $text_color = imagecolorallocate($im, 0, 0, 0); imagestring($im, 5, 150, 40, "YAZILIMBILISIM.NET", $text_color); imagedestroy($im); //$im dosyasının resource tipindedir. |
Bir değişken NULL türündeyse:
- Kendisine NULL sabiti atanmış demektir.
- Kendisine herhangi bir değer atanmamış demektir.
- unset() işlevine aktarılmış demektir.
1 2 3 4 5 6 | <?php $isim=NULL; echo $isim;//değer görünmemektedir. |
unknown type :dosya açıldığında yada oluşturulduğunda resource tipinde alınmaktadır. dosya kapatıldıktan yada bellekten boşaltıldıktan sonra php unknown tipinde değer döndürmektedir.
1 2 3 4 5 6 7 | <?php $f = fopen('https://placeholdit.imgix.net/~text?txtsize=33&txt=350×150&w=350&h=150','r'); echo gettype($f); // resource fclose($f); echo gettype($f); // unknown |