How to compare two strings in PHP
source link: https://www.laravelcode.com/post/how-to-compare-two-strings-in-php
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to compare two strings in PHP
Use the PHP strcmp()
function
You can use the PHP strcmp()
function to easily compare two strings. This function takes two strings str1
and str2
as parameters. The strcmp()
function returns < 0
if str1
is less than str2
; returns > 0
if str1
is greater than str2
, and 0 if they are equal.
Let's check out an example to understand how this function basically works:
<?php
$str1 = "Hello";
$str2 = "Hello World";
echo strcmp($str1, $str2); // Outputs: -6
?>
i hope you like this small article.
Author : Harsukh Makwana
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK