- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
strncmp() function in PHP
The strncmp() function is used to compare first n character.
Note − The function is case-sensitive.
Syntax
strncmp(str1, str2, len)
Parameters
str1 − The first string
str2 − The second string
len − The number of characters to use in the comparison.
Return
The strncmp() function returns −
0 - if the two strings are equal
<0 - if string1 is less than string2
>0 - if string1 is greater than string2
Example
The following is an example −
<?php echo strncmp("Demo text!","DEMO word!",4); ?>
Output
The following is the output −
8192
Example
Let us see another example −
<?php $str1 = "TomHanks"; $str2 = "tomhanks"; print_r(strncmp($str1, $str2, 8)); ?>
Output
The following is the output −
-32
Advertisements