Jump to content

Foreach script change


lindm

Recommended Posts

I have the function below to check if all form text fields of the selection are either zero or nothing. I realize it has the side effect that if field1 is 1000 and field2 is -1000 the functions returns the class value, which is not the purpose. Any suggestion for a script to check each text field individually it is either zero or contains nothing. If this is true for the arguments it returns the class value. Perhaps using an absolute value?

 

 

function rowx() {
$num = func_num_args(); //antal args

    $total = 0; 
    for( $i = 0; $i < $num; ++$i ) {
        $total += func_get_arg($i);
    }

    if ($total = 0 || $total =='') return 'class="h"';
}

 

Link to comment
https://forums.phpfreaks.com/topic/193946-foreach-script-change/
Share on other sites

You are using a single equal sign(=), that means assignment to PHP.

And just as a side note, an empty string and a null integer is the same, you can just pick one.

 

function rowx() {
$num = func_num_args(); //antal args

    $total = 0; 
    for( $i = 0; $i < $num; ++$i ) {
        $total += func_get_arg($i);
    }

    if ($total == null) return 'class="h"';
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.