# 2.1 Switch Case

## PHP'de `switch` ve `case` Nedir?

`switch` deyimi, bir değişkenin belirli bir değerle eşleşip eşleşmediğini kontrol etmek için kullanılır. Bu, çok sayıda `if` ve `else` deyimini kullanmak yerine daha temiz ve okunabilir bir alternatif sunar. Her bir olası değeri `case` deyimi ile belirtiriz. `break` deyimi, `switch` bloğunu sonlandırmak için kullanılır ve bir eşleşme bulunduktan sonra diğer `case` deyimlerinin çalışmasını engeller.

```php
switch (değişken) {
    case değer1:
        // kod bloğu
        break;
    case değer2:
        // kod bloğu
        break;
    default:
        // kod bloğu
}
```

> \[!NOTE]
>
> **`switch`**: Bir değişkenin farklı değerlere göre kontrol edilmesini sağlar. **`case`**: `switch` bloğu içinde kontrol edilecek her bir olası değeri belirtir.

```php
<?php
$gün = "Çarşamba";

switch ($gün) {
    case "Pazartesi":
        echo "Bugün Pazartesi.";
        break;
    case "Salı":
        echo "Bugün Salı.";
        break;
    case "Çarşamba":
        echo "Bugün Çarşamba.";
        break;
    default:
        echo "Hafta içi bir gün.";
}
?>
```

## `break` Nedir?

`break` deyimi, `switch` bloğunun sonlandırılmasını sağlar. Eğer `break` kullanılmazsa, eşleşen `case` bloğundan sonra gelen tüm `case` blokları da çalıştırılır (bu duruma "fall-through" denir).

> \[!NOTE]
>
> **`break`**: `switch` bloğunu sonlandırmak ve bir eşleşme bulunduktan sonra diğer `case` deyimlerinin çalışmasını engellemek için kullanılır.

```php
<?php
$gün = "Salı";

switch ($gün) {
    case "Pazartesi":
        echo "Bugün Pazartesi.";
    case "Salı":
        echo "Bugün Salı.";
    case "Çarşamba":
        echo "Bugün Çarşamba.";
    default:
        echo "Hafta içi bir gün.";
}
?>

```

## `default` Deyimi

`default` deyimi, hiçbir `case` ifadesi eşleşmediğinde çalışacak kod bloğunu belirtir. `default` isteğe bağlıdır ve kullanılmazsa hiçbir eşleşme olmadığında `switch` bloğu içindeki kod çalışmaz.

> \[!NOTE]
>
> **`default`**: Hiçbir `case` ifadesi eşleşmediğinde çalışacak kod bloğunu belirtir.

```php
<?php
$gün = "Pazar";

switch ($gün) {
    case "Pazartesi":
        echo "Bugün Pazartesi.";
        break;
    case "Salı":
        echo "Bugün Salı.";
        break;
    case "Çarşamba":
        echo "Bugün Çarşamba.";
        break;
    default:
        echo "Hafta içi değil.";
}
?>

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.yavuzlar.org/egitim/00x0-php-nedir/01x1-switch-case.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
