Jump to content

Macro substitution


gtener
Go to solution Solved by requinix,

Recommended Posts

function emptyzipcode($request) {
    global $requestslimit,$postal1,$postal2,$postal3,$postal4,$postal5,$postal6,$postal7,$postal8,$postal9,$postal10;

    $string = '(';
    for ($x = $request+1; $x <= 9; $x++) {
        $string = $string . '!empty($postal' . $x . ') or ';
    }

    $string = $string . '!empty($postal10))';
    $postal='postal'. $request;

    echo $string;    
    echo "<br/><br/>";
    echo $$postal;
    echo "<br/><br/>";
    echo $postal2;

    if (empty($$postal) and $$string){
        echo '<h2><font color="red">Failed!</font></h2>';
        echo '<h3>Request #' . $request . ' Zip Code Empty!</h3>';
        exit();
    }
}

I want to able to use the variable $string as a condition in the if statement; for example $string="(!empty($postal5) or !empty($postal6) or !empty($postal7) or !empty($postal8) or !empty($postal9) or !empty($postal10))"

Does anybody know how to do this? Thanks 

Link to comment
Share on other sites

That was too easy...

To make sure we're on the same page, I'm talking about replacing those 10 $postals with a single array containing up to 10 items.
Note the "up to". You only store the good values in there, meaning the whole "I have to check if they're empty" doesn't need to happen (at least not once the values are in there).
It also means you could store more than 10 if you wanted. Like (up to) 15. Or maybe you decide you have too many and want to lower it to having (up to) 5. Or whatever. And the code using the array wouldn't have to change.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.