[nycphp-talk] State table implementation ideas

Glenn glenn310b at
Sat Feb 4 19:33:12 EST 2006

On Feb 4, 2006, at 6:11 PM, tedd wrote:

> Cliff & Glenn:
> What, pray tell, are you guys doing?


Uh.. well.. uh..

I don't know exactly what Cliff is doing, but it seemed like he wanted 
to replace
a lot of conditional logic with something easier to maintain.
I'm having fun exploring possible solutions...

> Glen, I ran your code and received an "option_b" -- what does that
> mean? Is it fatal?

Probably to my reputation...


Here's the next revision of the logic...

I think it would be better to just define a list of fields that must 
ALL be true if an option
is to be displayed.

Then, if there are any fields that, if true, would cause the option NOT 
to be displayed
check for those.

Anyway, here's the code.



// If the status fields contain simple true or false values this might 

// example values for testing
$field_vals['field_a'] = 'y';
$field_vals['field_b'] = 'y';
$field_vals['field_c'] = 'y';
$field_vals['field_d'] = 'n';

// a list of all the fieldnames

$field_list = array('field_a','field_b','field_c','field_d');

// a list of all the options

$options = array('option_a','option_b','option_c');

// begin options maintenence area
// control options use here
// $trigger_include_option: if ALL of these fields are true,
// INclude the option on the options list
// $trigger_exclude_option: if ANY of these fields are true,
// EXclude the option from the options list

$trigger_include_option['option_a'] = 
$trigger_exclude_option['option_a'] = array('field_d');

$trigger_include_option['option_b'] = array('field_a','field_c');
$trigger_exclude_option['option_b'] = array('field_d');

$trigger_include_option['option_c'] = array('field_d');
$trigger_exclude_option['option_c'] = array('field_c');

// end of options maintenence area

// loop on the multidimensional array and set $use_option[$option]
// to either 'y' or 'n' for each conditional.
// when we're finished, if $use_option[$option] is set to 'y'
// we can use it.

foreach ($trigger_include_option as $option=>$field_list) {

    $use_option[$option] = 'n';

    foreach ($field_list as $field) {
       if ($field_vals[$field] == 'y') {
          $use_option[$option] = 'y';
       else {
          $use_option[$option] = 'n';


// check for any true fields that could exclude an option
// from the list

foreach ($trigger_exclude_option as $option=>$field_list) {

    foreach ($field_list as $field) {
       if ($field_vals[$field] == 'y') {
          $use_option[$option] = 'n';


// now show the available options

print "<ul>";

foreach($options as $option) {

    if ($use_option[$option] == 'y') {
       print "<li>$option</li>\n";


print "</ul>";

// cut and paste for debugging


<p>Program Execution Completed</p>

More information about the talk mailing list