PHP : Function Reference : String Functions : strncmp
anonymous
strncmp("sample","sam",4) returns 1 because the final requirement is if one string terminates before len, then the other must also terminate at that position.
You can imagine that all your strings have one more final, invisible "termination" character. If that termination character happens to be within in len, then it must match, too.
For instance, write that termination character with, say, the sequence "\0". Then you can equivalently consider that function call as strncmp("sample\0","sam\0",4).
So, the "p" in "sample" does not match the termination character in "sam".
|