PHP Diziler, Döngüler ve SERVER, GLOBAL ve REQUEST
PHP Dizi Tanımlama, Değer Atama ve Diziyi Listeleme
<?php echo "merhaha"; define(br, "<br>"); $isim = array("ufuk", "tas", "ayse","fatma","hayriye"); echo "<br>"; var_dump($isim); echo br; echo count($isim); echo br; for ($i=0; $i < count($isim); $i++) { echo ($i+1).". isim: ".$isim[$i]; echo br; } ?> <hr> <?php foreach ($isim as $ad) { echo $ad; echo br; } ?> <hr> <?php $s = 0; foreach ($isim as $ad) : $s++; echo ($s).". isim: ".$ad; echo br; endforeach; ?>
PHP Dizi Tanımlama, Değer Atama ve Diziyi Listeleme – 2
<?php echo "merhaha"; define(br, "<br>"); $isim = array("ufuk", "tas", "ayse","fatma","hayriye"); $isim[0] = "husnu"; $isim[5] = "husamettin"; $isim[7] = "husniye"; ?> <hr> <?php $s = 0; foreach ($isim as $ad) : $s++; echo ($s).". isim: ".$ad; echo br; endforeach; echo "<hr>"; for ($i=0; $i < count($isim); $i++) { echo ($i+1).". isim: ".$isim[$i]; echo br; } //6. elemanda hata veriyor ve ve yedinci elemani yazmiyor ?>
PHP İki Boyutlu Diziler
<?php define(br, "<br>"); $eleman = array( "ad" => "Ufuk", "soyad" => "Tas", "yas" => 21, "okul_no" => 9012, "telefon" => 789 ); $eleman["okul_no"] = "453"; foreach ($eleman as $ozellik) : echo ("Deger: ".$ozellik); echo br; endforeach; echo "<hr>"; ?> <hr> <?php foreach ($eleman as $anahtar => $deger) { echo $anahtar. ": ".$deger; echo br; } ?>
PHP İç İçe Diziler
<?php define(br, "<br>"); $eleman = array( "ad" => "Ufuk", "soyad" => "Tas", "yas" => 21, "okul_no" => 9012, "telefon" => array( "ev" => "2432342432", "cep" => "1231231231" ), ); echo "<hr>"; foreach ($eleman as $anahtar => $deger) : if ($anahtar == "telefon") { foreach ($eleman["telefon"] as $tel_key => $tel_value) { echo $tel_key. ": ".$tel_value; echo br; } } else { echo $anahtar. ". " .$deger; echo br; } endforeach; ?>
PHP İç İçe Diziler – 2
<?php define(br, "<br>"); $eleman = array( array("ufuk", "tas", 21), array("cuneyt", "tas", 22), array("hakan", "tas", 28) ); ?> <hr><?=$eleman[0][2];?> <hr><?=$eleman[1][1];?> <hr><?=$eleman[2][0];?>
PHP Fonksiyon Oluşturma ve Çalıştırma
<?php define(br, "<br>"); function deneme () { echo "Ekrana deneme yazdirilsin"; echo br; } deneme(); echo "<hr>"; echo "2 ile 5 in toplami = " .topla(2,5); function topla($a, $b) { return $a + $b; } ?>
PHP Tablo Çizen Fonksiyon
<?php /* define(br, "<br>"); funtion tabloCiz($satir, $sutun, $kenar_rengi, $kenar_kalinligi = 5, $basliklar) { echo "<table border='$kenar_kalinligi' style='border-color:$kenar_rengi'>"; for($i=0; $i<$satir; $i++) { echo "<tr>"; for ($j=0; $j < $sutun; $j++) { if ($i == 0) { echo "<td>".$basliklar[$j]."</td>"; } else echo "<td>asd</td>"; } echo "</tr>"; } echo "</table>"; } tabloCiz(3,6,"red","3px", array("Bir","Iki","Uc","Dort","Bes","Alti")); */ function tablo_ciz($satir, $sutun, $kenar_rengi, $kenar_kalinligi=5, $basliklar) { echo "<table border='$kenar_kalinligi' style='border-color: $kenar_rengi'>"; for ($i=0; $i<$satir ; $i++) { echo "<tr>"; for ($s=0; $s<$sutun ; $s++) { if ($i==0) echo "<td>".$basliklar[$s]."</td>"; else echo "<td>asd</td>"; } echo "</tr>"; } echo "</table>"; } tablo_ciz(5,10,"blue","3px", array("bir","iki","üç","dört","beş","altı","yedi","sekiz","dokuz","on")); ?>
PHP Global Dizisi ve Değişkenlere Her Noktadan Erişim
<?php define(br, "<br>"); $a = 5; $b = "bir"; $z = array("A", "B", "c"); function yazdir() { echo $GLOBALS["a"]." - ".$GLOBALS["b"]; echo "<hr>"; foreach ($GLOBALS["z"] as $a => $b) { echo $a." - ".$b; echo br; } } yazdir(); //$z = array("A", "B", "c"); //Hata verir ?>
PHP SERVER Dizisi ve Sunucu Hakkında Bilgiler
<?php define(br, "<br>"); echo $_SERVER['PHP_SELF']; echo br; echo $_SERVER['SERVER_NAME']; echo br; echo $_SERVER['HTTP_HOST']; echo br; echo $_SERVER['HTTP_REFERER']; echo br; echo $_SERVER['HTTP_USER_AGENT']; echo br; echo $_SERVER['SERVER_ADDR']; echo br; ?>
PHP Request ve Form’dan Gönderilen Değerleri Okuma
<!DOCTYPE html> <html> <head> <title>Ise yarar FORM yapimi</title> </head> <body> <form action="10.php"> Ad <input type="text" name="ad"><hr> Soyad <input type="text" name="soyad"><hr> Yas <input type="text" name="yas"><hr> <input type="submit" value="Gönder"> </form> <hr> <hr> <?php echo "Gönderilenler... <hr>"; echo "Ad : " .$_REQUEST['ad']."<hr>"; echo "Soyad : " .$_REQUEST['soyad']."<hr>"; echo "Yas : " .$_REQUEST['yas']."<hr>"; ?> </body> </html>
PHP Form İşlemleri
<!DOCTYPE html> <html> <head> <title>Ise yarar FORM yapimi - POST</title> </head> <body> <form action="11.php" method="POST"> Ad <input type="text" name="ad"><hr> Soyad <input type="text" name="soyad"><hr> Yas <input type="text" name="yas"><hr> <input type="submit" value="Gönder"> </form> <hr> <hr> <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { echo "Gönderilenler... <hr>"; echo "Ad : " .$_REQUEST['ad']."<hr>"; echo "Soyad : " .$_REQUEST['soyad']."<hr>"; echo "Yas : " .$_REQUEST['yas']."<hr>"; } ?> </body> </html>
1.481 Gösterim
[…] Hafta: PHP Diziler, Döngüler ve SERVER, GLOBAL ve REQUEST […]