A PHP Error was encountered

Severity: 8192

Message: Return type of CI_Session_files_driver::open($save_path, $name) should either be compatible with SessionHandlerInterface::open(string $path, string $name): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Filename: drivers/Session_files_driver.php

Line Number: 113

A PHP Error was encountered

Severity: 8192

Message: Return type of CI_Session_files_driver::close() should either be compatible with SessionHandlerInterface::close(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Filename: drivers/Session_files_driver.php

Line Number: 280

A PHP Error was encountered

Severity: 8192

Message: Return type of CI_Session_files_driver::read($session_id) should either be compatible with SessionHandlerInterface::read(string $id): string|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Filename: drivers/Session_files_driver.php

Line Number: 145

A PHP Error was encountered

Severity: 8192

Message: Return type of CI_Session_files_driver::write($session_id, $session_data) should either be compatible with SessionHandlerInterface::write(string $id, string $data): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Filename: drivers/Session_files_driver.php

Line Number: 223

A PHP Error was encountered

Severity: 8192

Message: Return type of CI_Session_files_driver::destroy($session_id) should either be compatible with SessionHandlerInterface::destroy(string $id): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Filename: drivers/Session_files_driver.php

Line Number: 303

A PHP Error was encountered

Severity: 8192

Message: Return type of CI_Session_files_driver::gc($maxlifetime) should either be compatible with SessionHandlerInterface::gc(int $max_lifetime): int|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Filename: drivers/Session_files_driver.php

Line Number: 344

A PHP Error was encountered

Severity: 8192

Message: setcookie(): Passing null to parameter #7 ($httponly) of type bool is deprecated

Filename: core/Input.php

Line Number: 410

PHP Foreach Döngüsü Kullanımı
Öneri ve Hata Raporu



Günün Sözü Sevemez kimse seni benim sevdiğim kadar

kategori PHP
oylama 2.9/5 yorum 0 yorum yazar Hakan Taşan tarih 18 Haziran 2015

Foreach döngüsü, diziler üzerinde kullanılır ve dizideki her bir elemana sırayla ulaşmamızı sağlar. Dizideki eleman sayısı kadar döngü oluşur. Çalışma prensibi; dizinin 0. indeksinden başlar ve foreach döngüsü otomatik olarak indeks sayısını 1 artırıp dizinin son indeksine kadar gelir. Her döngüde o indeksteki elemanı, oluşturacağımız yeni bir değişkene atar ve bu değişken sayesinde dizi elemanlarına ulaşırız.

Syntax

foreach ($dizi as $degisken) {
    dizi elemanlarına erişebileceğimiz kodlar
}

 

Açıklamada söylendiği gibi $dizi içerisindeki elemanlar döngü sayesinde tek tek $degisken'e atanır ve böylelikle her elemana erişebiliriz.

Örnek 1)

<?php
    $renkler = array("Kırmızı","Mavi","Sarı","Beyaz");

    foreach ($renkler as $tutucu) {
        echo "$tutucu ";
    }
?>

// Çıktı: Kırmızı Mavi Sarı Beyaz

 

Örnek 2) Anahtarlı Dizi

<?php
    $dizi = array(
        "Bir" => 1,
        "İki" => 2,
        "Dokuz"  => 9,
        "Beş" => 5
    );

    foreach ($dizi as $sayi => $rakam) {
        echo "$sayi ve $rakam <br>";
    }
?>

/* Çıktı:
Bir ve 1
İki ve 2
Dokuz ve 9
Beş ve 5
*/

 

paylaş Paylaş
oylama yap Oyla

makale yorumları YORUMLAR

Bu makale için yorum yazılmamış