2 回答
TA贡献1806条经验 获得超8个赞
我不确定您要做什么,所以我将“笼统地”回答这个问题。如果您想从这里进一步澄清,我可以稍后添加到我的答案中。但是,这几乎是您想要的 if/else 语句的结构:
<?php
if (some_condition) {
// Do some coding/analyzing/variable setup, etc
if (second_condition_with_data) {
// A condition was met based on the data you setup after the first condition
} else {
// The secondary condition was not met and this is the default
}
} else {
// Default circumstance if the original condition was not met
}
TA贡献1825条经验 获得超6个赞
<?php $box = $this->session->userdata("user");
if ($box->mobile_number && $box->email_address && $box->address1 && $box->account_number != NULL) {echo '';} else
{ echo'
<div class="bg-light shadow-sm rounded p-4 mb-4">
<h3 class="text-5 font-weight-400 d-flex align-items-center mb-3">Profile Completeness</h3>
<div class="row profile-completeness">';}
if ($box->mobile_number && $box->email_address && $box->address1 && $box->account_number != NULL) {echo '';} else
{
if ($box->mobile_number != NULL) {echo '
<div class="col-sm-6 col-md-3 mb-4 mb-md-0">
<div class="border rounded p-3 text-center"> <span class="d-block text-10 text-light mt-2 mb-3"><i class="fas fa-mobile-alt"></i></span> <span class="text-5 d-block text-success mt-4 mb-3"><i class="fas fa-check-circle"></i></span>
<p class="mb-0">Mobile Added</p></div>
</div>';
} else {echo'
<div class="col-sm-6 col-md-3 mb-4 mb-md-0">
<div class="border rounded p-3 text-center"> <span class="d-block text-10 text-light mt-2 mb-3"><i class="fas fa-mobile-alt"></i></span> <span class="text-5 d-block text-light mt-4 mb-3"><i class="far fa-circle"></i></span>
<p class="mb-0"><a class="btn-link stretched-link" href="">Add Mobile</a></p></div>
</div>';}}
if ($box->mobile_number && $box->email_address && $box->address1 && $box->account_number != NULL) {echo '';} else
{
if ($box->email_address != NULL) {echo '
<div class="col-sm-6 col-md-3 mb-4 mb-md-0">
<div class="border rounded p-3 text-center"> <span class="d-block text-10 text-light mt-2 mb-3"><i class="fas fa-envelope"></i></span><span class="text-5 d-block text-success mt-4 mb-3"><i class="fas fa-check-circle"></i></span>
<p class="mb-0">Email Added</p></div>
</div>';
} else {echo'
<div class="col-sm-6 col-md-3 mb-4 mb-md-0">
<div class="border rounded p-3 text-center"> <span class="d-block text-10 text-light mt-2 mb-3"><i class="fas fa-envelope"></i></span><span class="text-5 d-block text-light mt-4 mb-3"><i class="far fa-circle"></i></span>
<p class="mb-0"><a class="btn-link stretched-link" href="">Add Email</a></p></div>
</div>';}}
if ($box->mobile_number && $box->email_address && $box->address1 && $box->account_number != NULL) {echo '';} else
{
if ($box->address1 != NULL) {echo '
<div class="col-sm-6 col-md-3 mb-4 mb-sm-0">
<div class="border rounded p-3 text-center"> <span class="d-block text-10 text-light mt-2 mb-3"><i class="fas fa-address-card"></i></span> <span class="text-5 d-block text-success mt-4 mb-3"><i class="fas fa-check-circle "></i></span>
<p class="mb-0">Address Added</p></div>
</div>';
} else {echo'
<div class="col-sm-6 col-md-3 mb-4 mb-sm-0">
<div class="border rounded p-3 text-center"> <span class="d-block text-10 text-light mt-2 mb-3"><i class="fas fa-address-card"></i></span> <span class="text-5 d-block text-light mt-4 mb-3"><i class="far fa-circle "></i></span>
<p class="mb-0"><a class="btn-link stretched-link" href="">Add Address</a></p></div>
</div>';}}
if ($box->mobile_number && $box->email_address && $box->address1 && $box->account_number != NULL) {echo '';} else
{
if ($box->account_number != NULL) {echo '
<div class="col-sm-6 col-md-3">
<div class="border rounded p-3 text-center"> <span class="d-block text-10 text-light mt-2 mb-3"><i class="fas fa-university"></i></span><span class="text-5 d-block text-success mt-4 mb-3"><i class="fas fa-check-circle "></i></span>
<p class="mb-0">Bank Added</p></div>
</div></div>
</div>';
} else {echo'
<div class="col-sm-6 col-md-3">
<div class="border rounded p-3 text-center"> <span class="d-block text-10 text-light mt-2 mb-3"><i class="fas fa-university"></i></span><span class="text-5 d-block text-light mt-4 mb-3"><i class="far fa-circle "></i></span>
<p class="mb-0"><a class="btn-link stretched-link" href="">Add Bank</a></p></div>
</div></div>
</div>';}}?>
找到解决方案。丑陋的代码地狱。但它有效。
为每个子条件复制相同的父条件。
- 2 回答
- 0 关注
- 520 浏览
添加回答
举报