I am working with a multidimensional array that will contain a variable number of empty objects inside of it. I've written a script to simply unset() the empty ones, and it works fine. However, even without an echo() function, the non-empty values are being printed when my loop is run, and I cannot seem to figure out why.
An example of an array that would use run through my loop:
Array
(
[0] => Group Object
(
[_title] => <strong>Abdomen</strong><ul>
[_issues] => <li><strong>Ascites</strong>: 1</li><li><strong>Blood Clot</strong>: 2</li>
)
[1] => Group Object
(
[_title] => <strong>Air Sac</strong><ul>
[_issues] => <li><strong>Cloudy</strong>: 1</li>
)
[2] => Group Object
(
[_title] => <strong>Beak Treatment</strong><ul>
[_issues] => <li><strong>Severe</strong>: 3</li>
)
[3] => Group Object
(
[_title] =>
[_issues] =>
)
[4] => Group Object
(
[_title] =>
[_issues] =>
)
[5] => Group Object
(
[_title] => <strong>Crop</strong><ul>
[_issues] => <li><strong>Impacted</strong>: 2</li>
)
[6] => Group Object
(
[_title] => <strong>Feathering</strong><ul>
[_issues] => <li><strong>Soiled</strong>: 1</li>
)
[7] => Group Object
(
[_title] => <strong>Feet</strong><ul>
[_issues] => <li><strong>Swollen</strong>: 1</li>
)
[8] => Group Object
(
[_title] =>
[_issues] =>
)
[9] => Group Object
(
[_title] =>
[_issues] =>
)
[10] => Group Object
(
[_title] => <strong>Heart</strong><ul>
[_issues] => <li><strong>Compromised</strong>: 1</li>
)
[11] => Group Object
(
[_title] => <strong>Hock</strong><ul>
[_issues] => <li><strong>Clear Exudate</strong>: 2</li>
)
[12] => Group Object
(
[_title] =>
[_issues] =>
)
[13] => Group Object
(
[_title] =>
[_issues] =>
)
[14] => Group Object
(
[_title] =>
[_issues] =>
)
[15] => Group Object
(
[_title] => <strong>Kidney</strong><ul>
[_issues] => <li><strong>Injured</strong>: 2</li>
)
)
The foreach() loop that clears out the empty Objects inside of the array:
foreach ($issues as $key => $link) {
if ($issues[$key] != '') {
unset($issues[$key]);
}
}
And finally, the output that is printed when the loop is run:
<strong>Abdomen</strong><ul>
<li><strong>Ascites</strong>: 1</li>
<li><strong>Blood Clot</strong>: 2</li>
<strong>Air Sac</strong><ul>
<li><strong>Cloudy</strong>: 1</li>
<strong>Beak Treatment</strong><ul>
<li><strong>Severe</strong>: 3</li>
<strong>Crop</strong><ul>
<li><strong>Impacted</strong>: 2</li>
<strong>Feathering</strong><ul>
<li><strong>Soiled</strong>: 1</li>
<strong>Feet</strong><ul>
<li><strong>Swollen</strong>: 1</li>
<strong>Heart</strong><ul>
<li><strong>Compromised</strong>: 1</li>
<strong>Hock</strong><ul>
<li><strong>Clear Exudate</strong>: 2</li>
<strong>Kidney</strong><ul>
<li><strong>Injured</strong>: 2</li>
Obviously I just want the empty groups removed and nothing to be printed. Any help is appreciated.