I'm trying to unset
stdClass object inside foreach
loop. Here is my code:
<?php
if (isset($summaryResult)) {
foreach($summaryResult as $rows) { ?>
<tr>
<td><?php echo $rows->st_date;?></td>
<td>
<?php
if(($rows->st_time_09 == '')&&($rows->st_time_11 == '')&&($rows->st_time_13 == '')){echo $rows->st_time_07;}
elseif(($rows->st_time_07 == '')&&($rows->st_time_11 == '')&&($rows->st_time_13 == '')){echo $rows->st_time_09;}
elseif(($rows->st_time_07 == '')&&($rows->st_time_09 == '')&&($rows->st_time_13 == '')){echo $rows->st_time_11;}
elseif(($rows->st_time_07 == '')&&($rows->st_time_09 == '')&&($rows->st_time_11 == '')){echo $rows->st_time_13;}
else{}
?>
</td>
<td>
<?php
if(($rows->st_chlorine_09 == '')&&($rows->st_chlorine_11 == '')&&($rows->st_chlorine_13 == '')){echo $rows->st_chlorine_07;}
elseif(($rows->st_chlorine_07 == '')&&($rows->st_chlorine_11 == '')&&($rows->st_chlorine_13 == '')){echo $rows->st_chlorine_09;}
elseif(($rows->st_chlorine_07 == '')&&($rows->st_chlorine_09 == '')&&($rows->st_chlorine_13 == '')){echo $rows->st_chlorine_11;}
elseif(($rows->st_chlorine_07 == '')&&($rows->st_chlorine_09 == '')&&($rows->st_chlorine_11 == '')){echo $rows->st_chlorine_13;}
else{}
?>
</td>
<td>
<?php
if(($rows->st_time_15 == '')&&($rows->st_time_17 == '')&&($rows->st_time_19 == '')){echo $rows->st_time_21;}
elseif(($rows->st_time_21 == '')&&($rows->st_time_17 == '')&&($rows->st_time_19 == '')){echo $rows->st_time_15;}
elseif(($rows->st_time_21 == '')&&($rows->st_time_15 == '')&&($rows->st_time_19 == '')){echo $rows->st_time_17;}
elseif(($rows->st_time_21 == '')&&($rows->st_time_15 == '')&&($rows->st_time_17 == '')){echo $rows->st_time_19;}
else{}
?>
</td>
<td>
<?php
if(($rows->st_chlorine_21 == '')&&($rows->st_chlorine_17 == '')&&($rows->st_chlorine_19 == '')){echo $rows->st_chlorine_15;}
elseif(($rows->st_chlorine_21 == '')&&($rows->st_chlorine_15 == '')&&($rows->st_chlorine_19 == '')){echo $rows->st_chlorine_17;}
elseif(($rows->st_chlorine_21 == '')&&($rows->st_chlorine_15 == '')&&($rows->st_chlorine_17 == '')){echo $rows->st_chlorine_19;}
elseif(($rows->st_chlorine_15 == '')&&($rows->st_chlorine_17 == '')&&($rows->st_chlorine_19 == '')){echo $rows->st_chlorine_21;}
else{}
?>
</td>
<td>
<?php
if(($rows->st_time_23 == '')&&($rows->st_time_01 == '')&&($rows->st_time_03 == '')){echo $rows->st_time_05;}
elseif(($rows->st_time_05 == '')&&($rows->st_time_01 == '')&&($rows->st_time_03 == '')){echo $rows->st_time_23;}
elseif(($rows->st_time_05 == '')&&($rows->st_time_23 == '')&&($rows->st_time_03 == '')){echo $rows->st_time_01;}
elseif(($rows->st_time_05 == '')&&($rows->st_time_23 == '')&&($rows->st_time_01 == '')){echo $rows->st_time_03;}
else{}
?>
</td>
<td>
<?php
if(($rows->st_chlorine05 == '')&&($rows->st_chlorine01 == '')&&($rows->st_chlorine03 == '')){echo $rows->st_chlorine23;}
elseif(($rows->st_chlorine05 == '')&&($rows->st_chlorine23 == '')&&($rows->st_chlorine03 == '')){echo $rows->st_chlorine01;}
elseif(($rows->st_chlorine05 == '')&&($rows->st_chlorine23 == '')&&($rows->st_chlorine01 == '')){echo $rows->st_chlorine03;}
elseif(($rows->st_chlorine23 == '')&&($rows->st_chlorine01 == '')&&($rows->st_chlorine03 == '')){echo $rows->st_chlorine05;}
else{}
?>
</td>
</tr>
<?php
}
// unset($summaryResult); <== why this unset doesn't work ?
} else { ?>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<?php
} ?>
Above code is display the result like the following screenshot:
I want the data wrapping to 4 lines (check below screenshot) by unset
every object which already printed. I've put unset($summaryResult)
at the end 'foreach' loop but it doesn't work.
Any help would be appreaciated.
array_diff
andarray_filter
. Btw, those fields areString
. Is it possible to filter out the empty strings only according to above data ? – metaphor