In javascript we can use || to perform a second action if the first one fails, like:
function getObject(id_or_object) {
var obj = document.getElementById(id_or_object) || id_or_object;
return obj;
}
How can we do this in PHP?
If we can't, I can swear I have seen this || used like this in PHP. What does it mean?
I want to do:
function fix_item($item) {
$item['armor'] = $item['armor'] || 0;
return $item;
}
But this doesn't work, so I'm using
function fix_item($item) {
if (!isset($item['armor'])) $item['armor'] = 0;
return $item;
}
, but I don't like the second method.. Any ideas?