1
0
mirror of https://github.com/php/doc-zh.git synced 2026-03-24 15:12:20 +01:00
Files
archived-doc-zh/reference/array/functions/array-intersect-assoc.xml
2021-06-08 21:19:56 +08:00

130 lines
3.9 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 9e0f03ac354d797d1d16c0fcc1663e5e170f2727 Maintainer: daijie Status: ready -->
<refentry xml:id="function.array-intersect-assoc" xmlns="http://docbook.org/ns/docbook">
<refnamediv> <refname>array_intersect_assoc</refname>
<refpurpose>带索引检查计算数组的交集</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>array</type><methodname>array_intersect_assoc</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
<methodparam rep="repeat"><type>array</type><parameter>arrays</parameter></methodparam>
</methodsynopsis>
<simpara>
<function>array_intersect_assoc</function> 返回一个数组,该数组包含了所有在
<parameter>array</parameter> 和其它参数数组中同时存在的值。注意和
<function>array_intersect</function> 不同的是,键名也用于比较。
</simpara>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>array</parameter></term>
<listitem>
<para>
要检查的数组,作为主值。
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>arrays</parameter></term>
<listitem>
<para>
要被对比的数组。
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
返回一个关联数组,该数组包含了所有在
<parameter>array</parameter> 和其它参数数组中同时存在的值。
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>array_intersect_assoc</function> 例子</title>
<programlisting role="php">
<![CDATA[
<?php
$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
$array2 = array("a" => "green", "b" => "yellow", "blue", "red");
$result_array = array_intersect_assoc($array1, $array2);
print_r($result_array);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Array
(
[a] => green
)
]]>
</screen>
</example>
</para>
<simpara>
上面例子中可以看到,只有键值对 <literal>"a" =&gt;
"green"</literal> 在两个数组中都存在,从而被返回。
<literal>"red"</literal> 没有被返回,是因为在
<varname>$array1</varname> 中它的键名是 <literal>0</literal>
而在 <varname>$array2</varname> 中 "red" 的键名是
<literal>1</literal>,键 <literal>"b"</literal> 没有返回的原因是,它的值和其他数组不同。
</simpara>
<simpara>
仅在 <literal>(string) $elem1 === (string) $elem2 </literal> 时,
<literal>key =&gt; value</literal> 才被认为是相等的。
也就是说使用了严格的类型检查,字符串的表达形式必须相同。
<!-- TODO: example of it... -->
</simpara>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><function>array_intersect</function></member>
<member><function>array_uintersect_assoc</function></member>
<member><function>array_intersect_uassoc</function></member>
<member><function>array_uintersect_uassoc</function></member>
<member><function>array_diff</function></member>
<member><function>array_diff_assoc</function></member>
</simplelist>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->