Page 1 of 1

[GRIPE] range()

Posted: Tue Jun 27, 2006 1:49 pm
by hawleyjr
Wow, how did I miss this in the frigen manual range()
In PHP versions 4.1.0 through 4.3.2, range() sees numeric strings as strings and not integers. Instead, they will be used for character sequences. For example, "4242" is treated as "4".
What a pain. After a few hours of trying to figure out why some of my a list boxes were not working properly....the answer, php 4.3 :(

Posted: Tue Jun 27, 2006 1:59 pm
by RobertGonzalez
Learning something new about PHP everyday in this community...

And now someone else may not have a 'DOH!' moment because of your insight.

Posted: Tue Jun 27, 2006 2:04 pm
by Luke
yes, I was unaware of that as well. Thanks man

Posted: Tue Jun 27, 2006 2:10 pm
by hawleyjr
For anyone who cares here is a function that I tested in PHP 4.3 and PHP 5 :)

Code: Select all

/* ACCEPT TWO VALUES LOW AND HIGH
	RETURN AN ARRAY WITH THE RANGE OF VALUES LOW TO HIGH
*/
function getArrayFromRange($low_range,$high_range){

	if($low_range > $high_range){
		#REVERSE ARRAY
		$new_array = range((int)$high_range,(int)$low_range);
		$new_array = array_reverse($new_array);
	}else{
		$new_array = range((int)$low_range,(int)$high_range);
	}

	return $new_array;

}