array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'tr', ), 'this' => array ( 0 => 'function.sodium-memcmp.php', 1 => 'sodium_memcmp', ), 'up' => array ( 0 => 'ref.sodium.php', 1 => 'Sodium İşlevleri', ), 'prev' => array ( 0 => 'function.sodium-increment.php', 1 => 'sodium_increment', ), 'next' => array ( 0 => 'function.sodium-memzero.php', 1 => 'sodium_memzero', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/sodium/functions/sodium-memcmp.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 7 >= 7.2.0, PHP 8)
sodium_memcmp — Test for equality in constant-time
Compare two strings in constant-time.
In practice, you almost always want to use hash_equals() instead, since it provides the same logic but returns a bool instead of an int. However, if you're using the return value of a comparison in a calculation that's timing-sensitive, and worried about timing leaks with bool-to-int conversions, sodium_memcmp() is an ideal replacement.
string1
String to compare
string2
Other string to compare
Returns 0
if both strings are equal; -1
otherwise.