[GRIPE] range()

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

[GRIPE] range()

Post 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 :(
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

yes, I was unaware of that as well. Thanks man
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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;

}
Post Reply