我正在使用php构建的网站,当序列化字符串为空时,我想在其中隐藏div,img和p标签。
我使用序列化字符串的php代码是:
<div class="pickup-from-items-location">
<img src="/images/rsz_venueorange__1_.png">
<p class="mt-5 mb-5 font-weight-bold">pickup from item's location </p>
<div class="timings">
<?php
$serialized = '';
for ($i = 0; $i < count($data['item']->logistic_out); $i++) {
if(strcmp($data['item']->logistic_out[$i]->logistics_type, "location_pickup") == 0)
{
$serialized .= strtolower($data['item']->logistic_out[$i]->logistics_times);
}
}
if($serialized != '')
{
$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>
问题陈述:
if($serialized != '')
,我希望div p和img标签出现在if语句中。我尝试了以下代码,但似乎不起作用。
if($serialized != '')
{
echo
'<div class="pickup-from-items-location">
<img src="/images/rsz_venueorange__1_.png">
<p class="mt-5 mb-5 font-weight-bold">pickup from item's location
</p>';
$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>';
}
}
我想知道我需要在上面的代码中进行哪些更改,以便在序列化字符串为空时可以对p和img标签进行分割。