首页 > 解决方案 > 当值为空时,我想在页面上打印其他内容

问题描述

我有一个简单的代码,当银行名称为空并且站点 binlist 没有从在其位置写入其他内容的数据库中获取它时,我想要它,例如: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;

标签: php

解决方案


为什么不简单地检查它是否为空并在这种情况下分配值?

例如:

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


推荐阅读