Last Updated: February 25, 2016
·
237
· 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;
}