1
0
mirror of https://github.com/php/doc-zh.git synced 2026-03-25 23:52:17 +01:00
Files
archived-doc-zh/reference/array/functions/array-column.xml
Dai Jie 4ccc7d4408 translate for array_column fucntion
-- 
Provided by 邹松 ()

git-svn-id: https://svn.php.net/repository/phpdoc/zh/trunk@331119 c90b9560-bf6c-de11-be94-00142212c4b1
2013-08-13 09:40:04 +00:00

165 lines
4.1 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: beb09db76bd516580d32b751c5cb3b8388774b85 Maintainer: 邹松 Status: ready -->
<!-- Reviewed: no -->
<refentry xml:id="function.array-column" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>array_column</refname>
<refpurpose>返回数组中指定的一列</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>array</type><methodname>array_column</methodname>
<methodparam><type>array</type><parameter>input</parameter></methodparam>
<methodparam><type>mixed</type><parameter>column_key</parameter></methodparam>
<methodparam choice="opt"><type>mixed</type><parameter>index_key</parameter></methodparam>
</methodsynopsis>
<para>
<function>array_column</function>
返回<parameter>input</parameter>数组中键值为<parameter>column_key</parameter>的列,
如果指定了可选参数<parameter>index_key</parameter>,那么<parameter>input</parameter>数组中的这一列的值将作为返回数组中对应值的键。
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>input</parameter></term>
<listitem>
<para>
需要取出数组列的多维数组(或结果集)
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>column_key</parameter></term>
<listitem>
<para>
需要返回值的列,它可以是索引数组的列索引,或者是关联数组的列的键。
也可以是&null;,此时将返回整个数组(配合<parameter>index_key</parameter>参数来重置数组键的时候,非常管用)
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>index_key</parameter></term>
<listitem>
<para>
作为返回数组的索引/键的列,它可以是该列的整数索引,或者字符串键值。
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
从多维数组中返回单列数组
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>从结果集中取出first names列</title>
<programlisting role="php">
<![CDATA[
<?php
// Array representing a possible record set returned from a database
$records = array(
array(
'id' => 2135,
'first_name' => 'John',
'last_name' => 'Doe',
),
array(
'id' => 3245,
'first_name' => 'Sally',
'last_name' => 'Smith',
),
array(
'id' => 5342,
'first_name' => 'Jane',
'last_name' => 'Jones',
),
array(
'id' => 5623,
'first_name' => 'Peter',
'last_name' => 'Doe',
)
);
$first_names = array_column($records, 'first_name');
print_r($first_names);
?>
]]>
</programlisting>
&example.outputs;
<screen role="php">
<![CDATA[
Array
(
[0] => John
[1] => Sally
[2] => Jane
[3] => Peter
)
]]>
</screen>
</example>
</para>
<para>
<example>
<title>
从结果集中总取出last names列用相应的id作为键值
</title>
<programlisting role="php">
<![CDATA[
<?php
// Using the $records array from Example #1
$last_names = array_column($records, 'last_name', 'id');
print_r($last_names);
?>
]]>
</programlisting>
&example.outputs;
<screen role="php">
<![CDATA[
Array
(
[2135] => Doe
[3245] => Smith
[5342] => Jones
[5623] => Doe
)
]]>
</screen>
</example>
</para>
</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
-->