Example of comparing two strings to find the first different character position in PHP_PHP Tutorial

WBOY
Release: 2016-07-13 10:34:28
Original
821 people have browsed it

The general approach is like this:

Copy the codeThe code is as follows:

for ($offset = 0; $offset < $length; ++$offset) {
if ($str1[$offset] !== $str2[$offset]) {
return $offset;
}
}

The best answer given below is to use the XOR operator (^). I have never used this operator before, and I don’t know where it can be used. Today It's learned.

Because generally, when you perform an XOR operation on two strings, the XOR result of the same characters is null("

http://www.bkjia.com/PHPjc/750855.htmlwww.bkjia.com
true

http: //www.bkjia.com/PHPjc/750855.html

TechArticle
The general approach is like this: Copy the code as follows: ?php for ($offset = 0; $offset $ length; ++$offset) { if ($str1[$offset] !== $str2[$offset]) { return $offset; } } And the question...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template