<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.strings.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.strcmp.php',
    1 => 'strcmp',
    2 => '二进制安全字符串比较',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => '字符串 函数',
  ),
  'prev' => 
  array (
    0 => 'function.strchr.php',
    1 => 'strchr',
  ),
  'next' => 
  array (
    0 => 'function.strcoll.php',
    1 => 'strcoll',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/strings/functions/strcmp.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.strcmp" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">strcmp</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">strcmp</span> &mdash; <span class="dc-title">二进制安全字符串比较</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.strcmp-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>strcmp</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$string1</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$string2</code></span>): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>

  <p class="simpara">
   注意该比较区分大小写。
   对于不区分大小写的比较，请参见 <span class="function"><a href="function.strcasecmp.php" class="function">strcasecmp()</a></span>。
  </p>
  <p class="simpara">
   注意该比较不支持区域设置。如需支持区域设置的比较，请参见
   <span class="function"><a href="function.strcoll.php" class="function">strcoll()</a></span> 或 <span class="methodname"><a href="collator.compare.php" class="methodname">Collator::compare()</a></span>
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.strcmp-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">string1</code></dt>
     <dd>
      <p class="para">
       第一个字符串。
      </p>
     </dd>
    
    
     <dt><code class="parameter">string2</code></dt>
     <dd>
      <p class="para">
       第二个字符串。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.strcmp-returnvalues">
  <h3 class="title">返回值</h3>
  
  <p class="simpara">
   如果 <code class="parameter">string1</code> 小于 <code class="parameter">string2</code>，则返回小于 0 的值；
   如果 <code class="parameter">string1</code> 大于 <code class="parameter">string2</code>，则返回大于 0 的值；
   如果它们相等，则返回 <code class="literal">0</code>。
   除了它的符号外，不能从返回值中可靠推断出任何特定的含义。
  </p>

 </div>


 <div class="refsect1 changelog" id="refsect1-function.strcmp-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
 <td>8.2.0</td>
 <td>
  当字符串长度不相等时，此函数不再保证返回 <code class="literal">strlen($string1) - strlen($string2)</code>，
  而可能返回 <code class="literal">-1</code> 或 <code class="literal">1</code>。
 </td>
</tr>


    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.strcmp-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 <span class="function"><strong>strcmp()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$var1 </span><span style="color: #007700">= </span><span style="color: #DD0000">"Hello"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$var2 </span><span style="color: #007700">= </span><span style="color: #DD0000">"hello"</span><span style="color: #007700">;<br />if (</span><span style="color: #0000BB">strcmp</span><span style="color: #007700">(</span><span style="color: #0000BB">$var1</span><span style="color: #007700">, </span><span style="color: #0000BB">$var2</span><span style="color: #007700">) !== </span><span style="color: #0000BB">0</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">'$var1 is not equal to $var2 in a case sensitive string comparison'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>   
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.strcmp-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="itemizedlist">
    <li class="listitem">
     <span class="simpara">完整字符串比较</span>
     <ul class="simplelist">
      <li><span class="function"><a href="function.strcasecmp.php" class="function" rel="rdfs-seeAlso">strcasecmp()</a> - 二进制安全比较字符串（不区分大小写）</span></li>
      <li><span class="methodname"><a href="collator.compare.php" class="methodname" rel="rdfs-seeAlso">Collator::compare()</a> - Compare two Unicode strings</span></li>
      <li><span class="function"><a href="function.strcoll.php" class="function" rel="rdfs-seeAlso">strcoll()</a> - 基于区域设置的字符串比较</span></li>
     </ul>
    </li>
    <li class="listitem">
     <span class="simpara">部分字符串比较</span>
     <ul class="simplelist">
      <li><span class="function"><a href="function.substr-compare.php" class="function" rel="rdfs-seeAlso">substr_compare()</a> - 二进制安全比较字符串（从偏移位置比较指定长度）</span></li>
      <li><span class="function"><a href="function.strncmp.php" class="function" rel="rdfs-seeAlso">strncmp()</a> - 二进制安全比较字符串开头的若干个字符</span></li>
      <li><span class="function"><a href="function.strstr.php" class="function" rel="rdfs-seeAlso">strstr()</a> - 查找字符串的首次出现</span></li>
     </ul>
    </li>
    <li class="listitem">
     <span class="simpara">相似/其他字符串比较</span>
     <ul class="simplelist">
      <li><span class="function"><a href="function.preg-match.php" class="function" rel="rdfs-seeAlso">preg_match()</a> - 执行匹配正则表达式</span></li>
      <li><span class="function"><a href="function.levenshtein.php" class="function" rel="rdfs-seeAlso">levenshtein()</a> - 计算两个字符串之间的 Levenshtein 距离</span></li>
      <li><span class="function"><a href="function.metaphone.php" class="function" rel="rdfs-seeAlso">metaphone()</a> - Calculate the metaphone key of a string</span></li>
      <li><span class="function"><a href="function.similar-text.php" class="function" rel="rdfs-seeAlso">similar_text()</a> - 计算两个字符串的相似度</span></li>
      <li><span class="function"><a href="function.soundex.php" class="function" rel="rdfs-seeAlso">soundex()</a> - Calculate the soundex key of a string</span></li>
     </ul>
    </li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>