gmp_cmp()是PHP中的一個內置函數,用於比較兩個GMP編號(GNU多重精度:用於大數)。
用法:
gmp_cmp($num1, $num2)
參數:該函數接受兩個GMP數字$num1和$num2作為強製參數,如上麵的語法所示,用於比較。這些參數可以是PHP 5.6和更高版本中的GMP對象,或者也允許我們傳遞數字字符串,以便可以將這些字符串轉換為數字。
返回值:如果$num1> $num2,該函數返回“1”;如果$num1等於$num2,則返回“0”;如果$num1,則返回“-1”
例子:
Input : gmp_cmp("1234", "1236")
Output : -1
Input : gmp_cmp("3569", "3569")
Output : 0
以下示例程序旨在說明PHP中的gmp_cmp()函數:
程序1:程序將兩個GMP數字作為數字字符串傳遞時進行比較。
<?php 
// PHP program to compare two 
// GMP numbers passed as arguments  
   
// strings as GMP numbers  
$num1 = "12356"; 
$num2 = "12356"; 
  
// compares the two numbers and 
// gives the result "0" as both are equal  
$res = gmp_cmp($num1, $num2); 
  
echo $res; 
  
?>輸出:
0
程序2:程序將兩個GMP編號作為GMP編號作為參數傳遞時進行比較。
<?php 
  
// PHP program to compare two 
// GMP numbers passed as arguments  
  
// creating GMP numbers using gmp_init() 
$num1 = gmp_init(12355); 
$num2 = gmp_init(12356); 
  
// compares these two numbers and 
// gives the result "-1" as $num1 < $num2 
$res = gmp_cmp($num1, $num2); 
  
echo $res; 
?>輸出:
-1
參考:
http://php.net/manual/en/function.gmp-cmp.php
相關用法
- p5.js sq()用法及代碼示例
 - d3.js d3.map.has()用法及代碼示例
 - PHP next()用法及代碼示例
 - p5.js day()用法及代碼示例
 - p5.js pow()用法及代碼示例
 - CSS var()用法及代碼示例
 - d3.js d3.map.set()用法及代碼示例
 - PHP pow( )用法及代碼示例
 - PHP pi( )用法及代碼示例
 - PHP Ds\Map get()用法及代碼示例
 - PHP Ds\Map put()用法及代碼示例
 - p5.js str()用法及代碼示例
 
注:本文由純淨天空篩選整理自akash1295大神的英文原創作品 PHP | gmp_cmp() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
