我正在一个要检查空序列化字符串的网站上。我在问题陈述中提到了我的问题。
我在php中使用的代码是:
<!-----------------------------LEFT DIV ------------------------------->
<div class="pickup-from-items-location" id="pickup_from_items_location">
<div class="timings">
<?php
$serialized = '';
for ($i = 0; $i < count($data['item']->item_logistic); $i++) {
if(strcmp($data['item']->item_logistic[$i]->logistics_type, "location_pickup") == 0)
{
$serialized .= strtolower($data['item']->item_logistic[$i]->logistics_times);
}
}
if($serialized != '')
{
echo
'<div class="icons_text">
<img src="/images/rsz_venueorange__1_.png">
<p class="mt-4 mb-3 heading_size">pickup from item\'s location </p>
</div>';
/*
echo '<span class="font-weight-bold how-can-this-text">' . "how can this item be received" . '</span>';
echo "<br>";
echo "<br>";
echo '<span class="font-weight-bold mb-3 ml-3">' . "pickup from item's location <br/>" . '</span>';
echo "<br>";
echo "<br>"; */
$unserialized = unserialize( $serialized );
foreach($unserialized as $key=>$value)
{
echo '
<div class="dates_timings_items_availability">
<div class="items_availability_weekdays">'. strtolower(date('l', strtotime($key))) .':</div>
<div class="items_availability_time"><span>'. $value['start'] .'</span></div>
<div class="delimiter">to</div>
<div class="items_availability_time"><span>'. $value['end'] .'</span></div>
</div>';
}
}
else
{
/* echo "<p style=\"font-style: italic;\">No information available</p>"; */
}
?>
</div>
</div>
<!-----------------------------RIGHT DIV ------------------------------->
<div class="deliver-to-my-location">
<div class="timings">
<?php
$serialized = '';
for ($i = 0; $i < count($data['item']->item_logistic); $i++) {
if(strcmp($data['item']->item_logistic[$i]->logistics_type, "delivery") == 0)
{
$serialized .= strtolower($data['item']->item_logistic[$i]->logistics_times);
}
}
if($serialized != '')
{
echo
'<div class="icons_text">
<img src="/images/rsz_deliveryicon__1_.png">
<p class="mt-4 heading_size mb-3" style="width:100%;">deliver to my location </p>
</div>';
/*
echo "<br>";
echo "<br>";
echo '<span class="font-weight-bold mb-3 ml-3">' . "deliver to my location <br/>" . '</span>';
echo "<br>";
echo "<br>"; */
$unserialized = unserialize( $serialized );
foreach($unserialized as $key=>$value) {
echo '
<div class="dates_timings_items_availability">
<div class="items_availability_weekdays">'. strtolower(date('l', strtotime($key))) .':</div>
<div class="items_availability_time"><span>'. date('g:i a', strtotime($value['start'])) .'</span></div>
<div class="delimiter">to</div>
<div class="items_availability_time"><span>'. date('g:i a', strtotime($value['end'])) .'</span></div>
</div>';
}
}
?>
</div>
</div>
问题陈述:
我想知道应该应用什么逻辑,以便当左div为空时,右div应该向左移动。
当我使用上面的php代码时,左/右div在运行时变为空。
由于我使用上面的<div class="pickup-from-items-location"> <div class="timings">
条件,当$ serialized字符串为null时,示例if($serialized != '')
变为空。
[[LEFT] [RIGHT]]
左Div为<div class="pickup-from-items-location">
,Right Div为<div class="deliver-to-my-location">
因此,当“左Div”为空时,“右Div”应向左移动。
有可能吗?
[[RIGHT]]
答案 0 :(得分:0)
是的,最好的方法(在我看来)是根据 $ serialized 的值修改CSS。因此,当您不想显示[LEFT]时,请勿在浏览器中显示它。理论上(取决于html和css的设置方式),当不显示左侧列时,右侧应仅填充其位置。
为此;
首先,让我们将除了回声之外的所有逻辑移到HTML之外。
<?php
$serialized = '';
for ($i = 0; $i < count($data['item']->item_logistic); $i++) {
if(strcmp($data['item']->item_logistic[$i]->logistics_type, "location_pickup") == 0) {
$serialized .= strtolower($data['item']->item_logistic[$i]->logistics_times);
}
}
?>
然后,我们将为[LEFT]添加HTML和PHP
<div class="pickup-from-items-location" style="<?php if(!empty($serialized)) echo 'display: none;'; ?>" id="pickup_from_items_location">
<div class="timings">
<div class="icons_text">
<img src="/images/rsz_deliveryicon__1_.png">
<p class="mt-4 heading_size mb-3" style="width:100%;">deliver to my location </p>
</div>
<?php
if(!empty($serialized)) {
$unserialized = unserialize( $serialized );
foreach($unserialized as $key=>$value) {
?>
<div class="dates_timings_items_availability">
<div class="items_availability_weekdays">'. strtolower(date('l', strtotime($key))) .':</div>
<div class="items_availability_time"><span>'. date('g:i a', strtotime($value['start'])) .'</span></div>
<div class="delimiter">to</div>
<div class="items_availability_time"><span>'. date('g:i a', strtotime($value['end'])) .'</span></div>
</div>
<?php
}
}
?>
</div>
</div>
我建议对[RIGHT]重复类似的结构