How can you easily avoid getting this error/notice:
Notice: Undefined offset: 1 in /var/www/page.php on line 149
… in this code:
list($func, $field) = explode('|', $value);
There are not always two values returned by explode, but if you want to use list() how can you then easily avoid the notice?
Two changes:
explode()to 2. It seems, that no more than this is wantednulluntil the array contains 2 values. See Manual: array_pad() for further informationThis means, if there is no
|in$value,$field === null. Of course you can use every value you like to define as default for$field(instead ofnull). Its also possible to swap the behavior of$funcand$fieldNow
$funcisnull, when there is no|in$value.