I have a setter in which I need to pass a value from an array-element with a specific key.
- If the array key does not exist pass
null - If the element value is an empty string
''passnull - If the value is not empty string
'string or int or ...'- pass the value
What I have is this:
$obj->setValue(isset($array['a']) ? (!empty(trim($array['a'])) ? $array['a'] : null ) : null );
Some would argue that its hard to read. So - whats the "clean" way?
$obj->setValue(trim($array['a']) ?: null);. This will throw PHP Notice if key does not exist, but PHP Notice should be suppressed on production environment" "will be passed as""though :/