Shadowing Posted February 4, 2012 Share Posted February 4, 2012 Is there any way to have php filter out negitive numbers where it counts it as zero instead? so the math im doing in a string can never go negitive been looking online for a hour cant seem to find anything that does this. Quote Link to comment https://forums.phpfreaks.com/topic/256392-how-to-force-a-negitive-variable-to-0/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 4, 2012 Share Posted February 4, 2012 $num = ($num < 0) ? 0 : $num; Quote Link to comment https://forums.phpfreaks.com/topic/256392-how-to-force-a-negitive-variable-to-0/#findComment-1314431 Share on other sites More sharing options...
Shadowing Posted February 4, 2012 Author Share Posted February 4, 2012 Thanks for the reply PFMaBiSmAd I meant with out using a statement Quote Link to comment https://forums.phpfreaks.com/topic/256392-how-to-force-a-negitive-variable-to-0/#findComment-1314434 Share on other sites More sharing options...
PFMaBiSmAd Posted February 4, 2012 Share Posted February 4, 2012 Sorry, cannot help you without knowing all the conditions and context of what you are doing. You must have some kind of logic to test the value and produce/return the zero value for negative numbers. Even using a built-in or user written function would require the use of a statement. Now, if you will care to fully explain what it is you are trying to do and in what context, I'm sure someone can probably help you. Quote Link to comment https://forums.phpfreaks.com/topic/256392-how-to-force-a-negitive-variable-to-0/#findComment-1314436 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.