如何在php中检查空序列化字符串?

I am working on a website in which I want to check empty serialize string. I have mention my question in the problem statement.

The code which I am using in php is:

<!-----------------------------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>


Problem Statement:

I am wondering what logic I need to apply so that when left div is empty, right div should move towards the left.

The left/right div becomes empty at run time as I am using a php code above.

Example <div class="pickup-from-items-location"> <div class="timings"> becomes empty when $serialized string is null because I am using if($serialized != '') condition above.

      [[LEFT]                                              [RIGHT]]

Left Div is <div class="pickup-from-items-location"> and Right Div is <div class="deliver-to-my-location">

so when Left Div is empty, Right Div should move towards the left.

Is it possible ?

      [[RIGHT]]

Yes, the best way to approach this (in my opinion) would be to modify the CSS based on the value of $serialized. So when you don't want to show the [LEFT] simply do not display it in the browser. Theoretically (depending on how your html & css is setup) when the left column is not displayed the right should just populate it's spot.

To do this;

First, let's move all of your logic excluding echo's outside of your 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);
         }
     }
?>

Then, we'll add our HTML & PHP for the [LEFT]

<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>

I recommend repeating a similar structure for the [RIGHT]