1~

Minter Coder's Blog

11-PHP Math (PHP'de Matematik Kütüphanesi)

11-PHP Math

PHP çok fazla matematik fonksiyonu ve constanları (sabit değişkenleri) içerisinde bulundurur. Bunları örnekleriyle görelim.

  1. abs() : Bu fonksiyon içerisine verilen değişkeni pozitif yapar. Matematikte bildiğiniz mutlak değer gibi düşünün.

    <?php 
     echo abs(4.4); // Output : 4.4
     echo abs(-8.2); // Output : 8.2
    ?>
  2. round() : Bu fonksiyon içerisine verilen değişkeni en yakın değere yuvarlar.

    <?php 
     echo round(5.2); // Output : 5
     echo round(8.5); // Output : 9
     echo round(9.7); // Output : 10
    ?>
  3. ceil() : Bu fonksiyon içerisine verilen değişkeni bir üst değere yuvarlar.

    <?php 
     echo ceil(8.2); // Output : 9
     echo ceil(7.3); // Output : 8
     echo ceil(9.1); // Output : 10
    ?>
  4. floor() : Bu fonksiyon içerisine verilen değişkeni bir alt değere yuvarlar.

    <?php 
     echo floor(8.2); // Output : 8
     echo floor(9.7); // Output : 9
    ?>
  5. rand() : Bu fonksiyon random sayı üretmek için kullanılır.

    <?php 
     echo rand();
     echo rand(5,15); // 5 ile 15(dahil) arasında olmak üzere bir random sayı üretir.
    ?>
  6. sqrt() : Bu fonksiyon verilen sayının karekökünü alır.

    <?php 
     echo sqrt(36); // Output : 6
    ?>
  7. pi() : Bu fonksiyon PI değerini dönderir.

    <?php 
     echo pi();
    ?>
  8. max() : Bu fonksiyon içerisine verilen değişkenlerden hangisinin daha büyük olduğunu gösterir.

    <?php 
     echo max(42,9.4); // Output : 42
    ?>
  9. min() : Bu fonksiyon içerisine verilen değişkenlerin hangisinin daha küçük olduğunu gösterir.

    <?php 
     echo max(42,9.4); // Output : 9.4
    ?>
  10. pow() : Bu fonksiyon içerisine verilen değişkenin x üzeri y değerini alır.

    <?php 
     echo pow(2,4); // 2 üzeri 4 = 16
     echo pow(3,5); // 3 üzeri 5 = 243
    ?>
  11. log10() : Bu fonksiyon içerisine verilen değişkenin log10 tabanındaki değerini alır.

    <?php 
     echo log10(100); // Output : 2
    ?>