billw44 billw44 - 1 month ago 9
PHP Question

Loop through Array in php find value stop loop and echo header

foreach($resorts as $askiarea)
{

$askiarea = (array) $askiarea;

$askiarea['ReportType'] = $askiarea['resortStatus'];

$flag=1;


if (($askiarea['ReportType'] ==6) || ($askiarea['ReportType'] =="6"))
{

if($flag ==1)

echo '<tr><th colspan="6" text-align="left"><div class="region-headline">Opening Soon For Snow Sports</div></th></tr>';}

$flag = 0;


}

The header only need to be echoed once after the value is found for ReportType every time I try this I get multiply headers.

qkr qkr
Answer

Use break statement.

foreach($resorts as $askiarea) {
    $askiarea = (array) $askiarea;
    $askiarea['ReportType'] = $askiarea['resortStatus'];
    if (($askiarea['ReportType'] ==6) || ($askiarea['ReportType'] == "6")) {
        echo '<tr><th colspan="6" text-align="left"><div class="region-headline">Opening Soon For Snow Sports</div></th></tr>';}
        break;
    }
}

More about break here