PHP strcmp() 函数

<p>实例</p><p>比较两个字符串(区分大小写):</p><pre class="brush:php;toolbar:false">&lt;?php echostrcmp(&quot;Helloworld!&quot;,&quot;Helloworld!&quot;); ?&gt;</pre><p>定义和用法</p><p>strcmp() 函数比较两个字符串。</p><p>注释:strcmp() 函数是二进制安全的,且对大小写敏感。</p><p>提示:该函数与 strncmp() 函数类似,不同的是,通过 strncmp() 您可以指定每个字符串用于比较的字符数。</p><p>语法</p><p>strcmp(string1,string2)</p><p>参数<span class="Apple-tab-span" ></span>描述</p><p>string1<span class="Apple-tab-span" ></span>必需。规定要比较的第一个字符串。</p><p>string2<span class="Apple-tab-span" ></span>必需。规定要比较的第二个字符串。</p><p>技术细节</p><p>返回值:<span class="Apple-tab-span" ></span></p><p>本函数返回:</p><p>0 - 如果两个字符串相等</p><p>&lt;0 - 如果 string1 小于 string2</p><p>&gt;0 - 如果 string1 大于 string2</p><p>PHP 版本:<span class="Apple-tab-span" ></span>4+</p><p>更多实例</p><p>例子 1</p><p>比较两个字符串(区分大小写,Hello 和 hELLo 输出不相同):</p><pre class="brush:php;toolbar:false">&lt;?php echostrcmp(&quot;Hello&quot;,&quot;Hello&quot;); echo&quot;&lt;br&gt;&quot;; echostrcmp(&quot;Hello&quot;,&quot;hELLo&quot;); ?&gt;</pre><p>例子 2</p><p>不同的返回值:</p><pre class="brush:php;toolbar:false">&lt;?php echostrcmp(&quot;Helloworld!&quot;,&quot;Helloworld!&quot;);//两字符串相等 echostrcmp(&quot;Helloworld!&quot;,&quot;Hello&quot;);//string1大于string2 echostrcmp(&quot;Helloworld!&quot;,&quot;Helloworld!Hello!&quot;);//string1小于string2 ?&gt;</pre>
返回顶部 留言