我怎么能把这个 if 语句变成三元语句?
if ( !empty($vendor_address_row['address2'])){
$address_obj['address2'] = $vendor_address_row['address2'];
}else{
$address_obj['address2'] = '<tr><td colspan="1">'.$address_row['address2'].'</td></tr>';
}
我试过了
$vendor_address_row['address2'] ? $address_obj['address2'] = '<tr><td colspan="1">'.$address_row['address2'].'</td></tr>' : $address_obj['address2'] = '';
和
!empty($vendor_address_row['address2']) ? $address_obj['address2'] = '<tr><td colspan="1">'.$address_row['address2'].'</td></tr>' : $address_obj['address2'] = '';
都不工作。除此之外,可能还有更短的方法可以做到这一点。非常感谢。