php - 当值为空时,我想在页面上打印其他内容
问题描述
我有一个简单的代码,当银行名称为空并且站点 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;
解决方案
为什么不简单地检查它是否为空并在这种情况下分配值?
例如:
$bankname = empty($details['bank']['name']) ? 'N/A' : strtoupper($details['bank']['name']);
推荐阅读
- npm - 找不到模块:无法解析 gatsby 健全项目中的“@react-icons/all-files”
- node.js - 我尝试在本地计算机上全局安装 ionicons,但出现以下错误
- ios - 打开通用链接不会在应用程序中打开
- selenium - 即使 system.set 属性文件中的键和值正确,我也无法启动 Chrome 浏览器
- arrays - 如何在每行中显示两列是Scrollview而不是Flatlist?反应原生
- node.js - 无效响应和空 API 响应 - Alexa 对话问题
- python - 如何在openCV中获取带有视频输入的屏幕大小?
- python - TypeError:“dict”和“int”的实例之间不支持“>”
- python - 您可以将列表存储到while循环内的列表中吗?
- javascript - 通过javascript更改输入文本后事件侦听器不会触发