
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
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
- Related Articles
- What is strncmp() Function in C language?
- Write a C program to compare two strings using strncmp library function
- filter_has_var() function in PHP
- filter_id() function in PHP
- filter_input() function in PHP
- filter_input_array() function in PHP
- filter_list() function in PHP
- filter_var_array() function in PHP
- filter_var() function in PHP
- constant() function in PHP
- define() function in PHP
- defined() function in PHP
- die() function in PHP
- eval() function in PHP
- exit() function in PHP

Advertisements