jeudi 2 décembre 2021

how to compare number (0,1,2, -1, -1.5) and text values ​in php

I have a form to fill in the examination data. The form is filled in by a doctor, the data to be filled can also be numbers or text and I store this type of data in the table ex: 0 for numeric data types and 1 for text. when the form is saved, I will compare the data results with the specified standard value, so if the inspection result is greater than the standard value, it will produce a critical value or vice versa. for now I'm comparing the values ​​using the if else condition. is there a more efficient way than using the if else condition because the method I use currently still has bugs, ex: if the value is minus then the result that comes out doesn't match or if the text contains characters (+) or (-) then error result.

if( ($data_type== 0) || is_numeric($standart_value->MIN_VALUE) && is_numeric($standart_value->MAX_VALUE) ){

  if( ( floatval($v['result']) >= floatval($standart_value->MIN_VALUE) ) && ( floatval($v['result']) <= floatval($standart_value->MAX_VALUE) ) ){

    $is_normal = 1;

   }else{

    $is_normal = 0;

  }
  
}elseif( ($data_type== 1) || !is_numeric($standart_value->MIN_VALUE) && !is_numeric($standart_value->MAX_VALUE) ){

  $min = strtoupper($standart_value->MIN_VALUE);
  $max = strtoupper($standart_value->MAX_VALUE);
  $value = strtoupper($v['result']);

  if( ( preg_match_all("|$min|i", $value ) ) || ( preg_match_all("|$max|i", $value ) ) ){
                        
       $is_normal = 1;
         
  }else{
                        
       $is_normal = 0;
      
   }

}


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/31mRF3a
via IFTTT

Aucun commentaire:

Enregistrer un commentaire