Javatpoint Logo
Javatpoint Logo

PHP strncmp() Function

The strncmp() is predefine string function of PHP. It is used to compare two strings. This function strncmp() is binary-safe, case-sensitive and similar to strcmp() function but strcmp() have no the length parameter.

The strncmp () function is often used in programming and web development for string operation.

Syntax:

Parameter Description Required/Optional
String1 Specify the first string to compare Required
String2 Specify the second string to compare Required
Length Specify the number of character for comparison. Required

The strncmp () function:

  • Returns 0 : if the two string is equal.
  • Returns <0 : if string 1 is less than string2.
  • Return >0 : if string1 is greater than string 2.

Example 1

Output:

By using 'strcmp()' function: 0

Example 2

Output:

By using 'strcmp()' function:-9

Example 3

Output:

By using 'strcmp()' function:9

See Also :

  • str_word_count() : It is used to count the number of words in a string.
  • strcasecmp() : It is used to compare two strings.
  • strchr() : It is used to find the first occurrence of a string inside another string.

Reference:

http://php.net/manual/en/function.strncmp.php


Next TopicPHP String




Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA