Last Updated: February 25, 2016
·
262
· nickel715

prevent undefined index error

$array = [];
$foo = $array['nonExistingKey']; // throw E_NOTICE: Undefined index
if (!empty($foo)) 
{
    echo $foo;
}

use instead

$array = [];
$foo = &$array['nonExistingKey'];
if (!empty($foo)) 
{
    echo $foo;
}