Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
compare
communitycreator

What is gmp_cmp in PHP?

Hammad Nasir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

gmp_cmp is a function in PHP that is used to compare two numbers passed in as arguments.

Syntax

gmp_cmp(GMP|int|string $num1, GMP|int|string $num2): int

Parameters

The function takes in two parameters, num1 and num2.

num1 and num2 can be a numeric string, GMPGNU Multiple Precision Arithmetic Library object, or of type int.

Return value

  • The function returns a negative value if num2 is greater than num1.
  • The function returns a positive value if num1 is greater than num2.
  • The function returns zero if num1 is equal to num2.

Code

<?php
$val1 = gmp_cmp("1500", "1000");
echo "$val1\n";
$val2 = gmp_cmp("1000", "1534");
echo "$val2\n";
$cmp3 = gmp_cmp("1000", "1000");
echo "$val3\n";
?>

Expected output

1
-1
0

RELATED TAGS

php
compare
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring