Skip to content
Advertisement

When the value is empty, I want to print something else on a page

I have a simple code that I want when the name of a bank is empty and a site binlist has not obtained it from a database that writes something else in its place, for example : N/A

$BIN  = str_replace(' ', '',$PCT);
$BIN  = substr($BIN, 0, 6);
$url = "https://lookup.binlist.net/" . $BIN;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($ch);
curl_close($ch);
$details = json_decode($resp, true);
$countryname = strtoupper($details['country']['name']);
$cardtype = ucwords($details['type']);
$cardbrand = ucwords($details['brand']);
$bankname = strtoupper($details['bank']['name']);
$_SESSION['bankname'] = $bankname;

Advertisement

Answer

Why not simply check if it empty and assign the value in this case?

For example:

$bankname = empty($details['bank']['name']) ? 'N/A' : strtoupper($details['bank']['name']);

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement