lindm Posted March 2, 2010 Share Posted March 2, 2010 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 More sharing options...
ferdi Posted March 2, 2010 Share Posted March 2, 2010 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"'; } Link to comment https://forums.phpfreaks.com/topic/193946-foreach-script-change/#findComment-1020685 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.