How To Convert A Value To Non-negative Integer

How can I use PHP to convert a value to non-negative integer

You can use abs function to convert a negative to positive value and use intval function to convert a float or double number to interger.

$number = -1.56
$newnumber = abs( intval( $number ) ); // return 1
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments