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