Php
// Declaring strings
$name1
=
"Geeks"
;
$name2
=
"Geeks"
;
// Use the == operator
if
(
$name1
==
$name2
) {
echo
’Both strings are equal’
;
}
else
{
echo
’ Both strings are not equal’
;
}
?>
Exit:Both strings are equalstrcmp() function
Strcmp() - it is a built-in function in PHP that is used to compare two strings. This function is case sensitive, which indicates that uppercase and small cases will be handled differently during comparison. This function compares two strings and reports whether the first string is greater than or less than or equal to the second.Syntax:
strcmp ($string1, $string2)Parameters:This function takes two parameters as above and described below:
- $string1:this the parameter refers to the first line to be used in the comparison. This parameter is required.
- $string2:This parameter refers to the second string to be used in the comparison. This parameter is required.
Returned values:the function returns a random integer value depending on the match condition, which is specified as:
- Returns 0 if the strings are equal.
- Returns a negative value (< 0) if $string2 is greater than $string1.
- Returns a positive value (> 0 ) if $string1 is greater than $string2.
php
// Declaring strings
$name1
=
"Geeks"
;
$name2
=
"engineer"
;
// Using the strcmp() function
if
(
strcmp
(
$name1
,
$name2
)! == 0) {
echo
’Both strings are not equal’
;
}
else
{
echo
’ Both strings are equal’
;
}
?>
Exit:Both strings are not equalLink :
- http://php.net/manual/en/language.operators.comparison.php
- http://php.net/manual/en/function.strcmp.php