Jump to content

[SOLVED] if Decimal starts with, return XXXXX


Jarod

Recommended Posts

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!

<?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"

 

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.