How to compare two strings in PHP

How to compare two strings in PHP

In this post we will give you information about How to compare two strings in PHP. Hear we will give you detail about How to compare two strings in PHPAnd how to use it also give you demo for it if it is necessary.

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.

Hope this code and post will helped you for implement How to compare two strings in PHP. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US