Skip to content

Instantly share code, notes, and snippets.

@lenivene
Last active March 1, 2016 20:48
Show Gist options
  • Save lenivene/cee26986776de570a5f8 to your computer and use it in GitHub Desktop.
Save lenivene/cee26986776de570a5f8 to your computer and use it in GitHub Desktop.
Check if number is positive | negative
<?php
/*
* Check number is positive
* PHP Version required >= 4.0
*/
function is_num_negative( $num ){
if( empty( trim( $num ) ) || ! is_numeric( $num ) ){
return;
}
/*
* Zero is number neutral
* Example: If on a seesaw two people stay in middle, What happens? Do you understand?
*/
if( $num <= -1 ){
return true;
}else{
return;
}
}
<?php
/*
* Check number is positive
* PHP Version required >= 4.0
*/
function is_num_positive( $num ){
if( empty( trim( $num ) ) || ! is_numeric( $num ) ){
return;
}
/*
* Zero is number neutral
* Example: If on a seesaw two people stay in middle, What happens? Do you understand?
*/
if( $num >= 1 ){
return true;
}else{
return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment