Jump to content

About a function that evaluates some parameters


Ab

Recommended Posts

Hi all,

 

 

I am having a problem when doing float comaprisons such as this if ($point == 1.5 ), I wrote a function that gets  parameter, the parameters passed to this function are as follows: (1, 1.5,0.5,0, -1.5,-1 ). my goal is to set a star for each of these parameters values  (e.g 1= 5stars,1.5= 3stars ...ecc) using an array as lookup table. I am having problem when evaluating the float numbers such this (1.5..) so I can choose the matching star from the Star Array:here is the code:

 

I thank you in advance for all your help.

 


function Bev_DisplayStars($point)
{

$StarCount;

$Stars =  array(

               //Stars

               1 => '5 star',

               2 => '4 star',

               3 => '3 star',

               4 => '0 star',

               5 => '0 star',

               6 => '0 star',

               7 => '0 star',

               8 => '0 star',

               9 => '0 star',

              10 => '0 star');

                              
  if ($point == 1 )
   {

            
         $StarCount = $Stars[$point];          

   }  

   else if ($point = round(1.5) )

   {

       //$point = 2;

       $StarCount = $Stars[$point]; 

   }   

   else if ($point = round(0.5))

   {

     $StarCount = $Stars[$point];   

   }

   else if ($point == -1 )

   {

       //$point = 3;

       $StarCount = $Stars[10]; 

   }

   else 

   {

        $point = 5;

        $StarCount = $Stars[$point]; 
   

   }

return $StarCount;

}


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.