Quick Answer

Omgaan met niet-bestaande array keys.

Understanding the Issue

Komt voor bij toegang tot niet-bestaande array-elementen. Vaak bij $_POST, $_GET of $_SESSION arrays.

The Problem

This code demonstrates the issue:

Php Error
<?php
echo $_GET["niet_bestaande_key"]; // Notice

The Solution

Here's the corrected code:

Php Fixed
<?php
// Oplossing 1: Controleren met isset()
if (isset($_GET["key"])) {
    echo $_GET["key"];
}

// Oplossing 2: Null coalescing operator (PHP 7+)
echo $_GET["key"] ?? "standaard";

// Oplossing 3: Ternary operator
echo isset($_GET["key"]) ? $_GET["key"] : "standaard";

Key Takeaways

Controleer altijd of array keys bestaan voordat je ze gebruikt.