PHP Knowledge Base

Loop through an array of variables

Simple Example

$cwo__array = array($default__table, $default__year, $default__month);
$arrlength = count($cwo__array);

for($x = 0; $x < $arrlength; $x++) {
    echo nl2br($cwo__array[$x]."\n");
}

More Complicated Example

for($x = 0; $x < $arrlength; $x++) {
    if (isset($cwo__array[$x]) && !empty($cwo__array[$x])) {
		echo nl2br("<span class=\"txtGreen\">Variable present...</span>\n", false);
	} else {
		echo nl2br("<span class=\"txtRed\">Variable NOT present...</span>\n", false);
	}
}

Practical Example

$i = 0;

for($x = 0; $x < $arrlength; $x++) {
    if (isset($cwo__array[$x]) && !empty($cwo__array[$x])) {
		$i++;
	}
}

if ( $i < $arrlength ) {
	echo nl2br("<span class=\"txtRed\">CANNOT PROCEED: Not all variables present...</span>\n", false);
} else {
	echo nl2br("<span class=\"txtGreen\">SAFE TO PROCEED: All variables present...</span>\n", false);
}
NULL