Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php

What is gmp_mod() in PHP?

Abhilash

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.

Overview

The gmp_mod() function in PHP is used for the modulo operation. It accepts two parameters, such as, num1 and num2. The method calculates num1 modulo num2, such as, num1 % num2. The sign of num2 is ignored, and the result is always positive.

Syntax

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

Parameters

  • num1: This parameter can be a GMP object, integer, or a string.
  • num2: This parameter can be a GMP object, integer, or a string.

Return value

The method returns a GMP object which is the result of num1 mod num2.

Code example

Let’s look at the code below:

<?php
$remainder = gmp_mod(11, 7);
print "11 mod 7 = ".$remainder."\n";
$remainder = gmp_mod("15", 2);
print "15 mod 2 = ".$remainder."\n";
?>
gmp_mod() method

Code explanation

  • Line 2: We obtain 11 mod 7 by invoking gmp_mod() function and pass 11 and 7 as arguments.
  • Line 3: We print the obtained value of remainder/mod value.
  • Line 5: We obtain 15 mod 2 by invoking gmp_mod() function and pass 15 and 2 as arguments. Here, 15 is passed as a string.
  • Line 6: We print obtained the remainder/mod value.

RELATED TAGS

php

CONTRIBUTOR

Abhilash
Copyright ©2022 Educative, Inc. All rights reserved

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