In JavaScript I can do the following:
var variable = {
variable: arg || "bla";
}
// variable.variable = "bla" if arg is false, null or unefined
var variable [
arg || "bla
]
// variable[0] = "bla" if arg is false, null or unefined
If arg isn't defined, the value gets "bla". Pretty neat. I love this!
Is there something similiar possible in php? I can do an if with an isset(), but that produces a lot of code, especially if I have an array like this for example:
$postData = array(
'birthday' => $aData['oBirthday'] /* ????? */,
'country' => $aData['sCountry'],
'first_name' => $aData['sFirstName'],
'last_name' => $aData['sLastName']
);
EDIT:
The shortest syntax possible I found so far (Thanks to Tom!):
$postData = array(
'birthday' => isset($aData['oBirthday']) ? $aData['oBirthday'] : "aaaaaaaa"
);