Jarod Posted November 6, 2009 Share Posted November 6, 2009 Hi, I'm having a problem trying to figure out how I would make my script return the type of the decimal it is, which would be: Reset Mode, Recommended, Hot!, and Dangerous! To achieve this; the decimal's first number, beside zero, would determine the its statues. If the decimal starts with 1 it outputs Reset Mode, if 2 it outputs Recommended, if 3 it outputs Hot! and if 4 and/or above it outputs Dangerous!. How do I go on about this? Example: 0.00000435345323 Output: This decimal is in Dangerous mode! Link to comment https://forums.phpfreaks.com/topic/180503-solved-if-decimal-starts-with-return-xxxxx/ Share on other sites More sharing options...
highrevhosting Posted November 6, 2009 Share Posted November 6, 2009 <?php function wx($var) { $values = array('1'=>'Reset Mode','2'=>'Recommended','3'=>'HOT!','4'=>'Dangerous!'); $length = strlen($var); for($i=0;$i<=$length;$i++) { $temp = substr($var,$i,1); if($temp != '0' && $temp != '.'){ $i = $length + 10; if($temp>=4){ return $values[4]; }else{ return $values[$temp]; } } } } echo wx('0.0000234'); ?> Test this and it works. This outputs "Recommended" Link to comment https://forums.phpfreaks.com/topic/180503-solved-if-decimal-starts-with-return-xxxxx/#findComment-952384 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.