-
Notifications
You must be signed in to change notification settings - Fork 109
feat: 新增 array_any,array-find-key,array-find 的翻译 #1035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
singi2016cn
wants to merge
2
commits into
php:master
Choose a base branch
from
singi2016cn:feature-array_all_array_find_key_array_find
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- $Revision$ --> | ||
| <!-- EN-Revision: 679cf93fa1e54cde82fc9cf545966eb13bcb0638 Maintainer: Singi Status: ready --> | ||
| <!-- CREDITS: Singi --> | ||
| <refentry xml:id="function.array-all" xmlns="http://docbook.org/ns/docbook"> | ||
| <refnamediv> | ||
| <refname>array_all</refname> | ||
|
|
@@ -26,7 +27,7 @@ | |
| <term><parameter>array</parameter></term> | ||
| <listitem> | ||
| <simpara> | ||
| 需要被遍历的 &array; | ||
| 需要被遍历的 &array;。 | ||
| </simpara> | ||
| </listitem> | ||
| </varlistentry> | ||
|
|
@@ -57,7 +58,7 @@ | |
| <refsect1 role="examples"> | ||
| &reftitle.examples; | ||
| <example> | ||
| <title><function>array_all</function> 示例</title> | ||
| <title><function>array_all</function></title> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已修改 |
||
| <programlisting role="php"> | ||
| <![CDATA[ | ||
| <?php | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- $Revision$ --> | ||
| <!-- EN-Revision: 679cf93fa1e54cde82fc9cf545966eb13bcb0638 Maintainer: Singi Status: ready --> | ||
| <refentry xml:id="function.array-any" xmlns="http://docbook.org/ns/docbook"> | ||
| <refnamediv> | ||
| <refname>array_any</refname> | ||
| <refpurpose>检查数组中是否至少有一个元素满足回调函数的条件</refpurpose> | ||
| </refnamediv> | ||
|
|
||
| <refsect1 role="description"> | ||
| &reftitle.description; | ||
| <methodsynopsis> | ||
| <type>bool</type><methodname>array_any</methodname> | ||
| <methodparam><type>array</type><parameter>array</parameter></methodparam> | ||
| <methodparam><type>callable</type><parameter>callback</parameter></methodparam> | ||
| </methodsynopsis> | ||
| <simpara> | ||
| 如果指定的 <parameter>callback</parameter> 对任意一个元素返回 &true;,则 <function>array_any</function> 函数返回 &true;;否则该函数返回 &false;。 | ||
| </simpara> | ||
| </refsect1> | ||
|
|
||
| <refsect1 role="parameters"> | ||
| &reftitle.parameters; | ||
| <variablelist> | ||
| <varlistentry> | ||
| <term><parameter>array</parameter></term> | ||
| <listitem> | ||
| <simpara> | ||
| 需要被遍历的 &array;。 | ||
| </simpara> | ||
| </listitem> | ||
| </varlistentry> | ||
| <varlistentry> | ||
| <term><parameter>callback</parameter></term> | ||
| <listitem> | ||
| <para> | ||
| 用于检查每个元素的回调函数,该函数必须 | ||
| <methodsynopsis> | ||
| <type>bool</type><methodname><replaceable>callback</replaceable></methodname> | ||
| <methodparam><type>mixed</type><parameter>value</parameter></methodparam> | ||
| <methodparam><type>mixed</type><parameter>key</parameter></methodparam> | ||
| </methodsynopsis> | ||
| 如果该函数返回 &true;,则 <function>array_any</function> 会立即返回 &true;,并且不会再为后续元素调用该回调函数。 | ||
| </para> | ||
| </listitem> | ||
| </varlistentry> | ||
| </variablelist> | ||
| </refsect1> | ||
|
|
||
| <refsect1 role="returnvalues"> | ||
| &reftitle.returnvalues; | ||
| <simpara> | ||
| 如果数组中至少存在一个元素能让 <parameter>callback</parameter> 返回 &true;,则该函数返回 &true;;否则返回 &false;。 | ||
| </simpara> | ||
| </refsect1> | ||
|
|
||
| <refsect1 role="examples"> | ||
| &reftitle.examples; | ||
| <example> | ||
| <title><function>array_any</function></title> | ||
| <programlisting role="php"> | ||
| <![CDATA[ | ||
| <?php | ||
| $array = [ | ||
| 'a' => 'dog', | ||
| 'b' => 'cat', | ||
| 'c' => 'cow', | ||
| 'd' => 'duck', | ||
| 'e' => 'goose', | ||
| 'f' => 'elephant' | ||
| ]; | ||
|
|
||
| // Check, if any animal name is longer than 5 letters. | ||
| var_dump(array_any($array, function (string $value) { | ||
| return strlen($value) > 5; | ||
| })); | ||
|
|
||
| // Check, if any animal name is shorter than 3 letters. | ||
| var_dump(array_any($array, function (string $value) { | ||
| return strlen($value) < 3; | ||
| })); | ||
|
|
||
| // Check, if any array key is not a string. | ||
| var_dump(array_any($array, function (string $value, $key) { | ||
| return !is_string($key); | ||
| })); | ||
| ?> | ||
| ]]> | ||
| </programlisting> | ||
| &example.outputs; | ||
| <screen> | ||
| <![CDATA[ | ||
| bool(true) | ||
| bool(false) | ||
| bool(false) | ||
| ]]> | ||
| </screen> | ||
| </example> | ||
| </refsect1> | ||
|
|
||
| <refsect1 role="seealso"> | ||
| &reftitle.seealso; | ||
| <simplelist> | ||
| <member><function>array_all</function></member> | ||
| <member><function>array_filter</function></member> | ||
| <member><function>array_find</function></member> | ||
| <member><function>array_find_key</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 | ||
| --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- $Revision$ --> | ||
| <!-- EN-Revision: 596c11440dc232b8ed1836d7e3afe2ed5b225a7b Maintainer: Singi Status: ready --> | ||
| <refentry xml:id="function.array-find-key" xmlns="http://docbook.org/ns/docbook"> | ||
| <refnamediv> | ||
| <refname>array_find_key</refname> | ||
| <refpurpose>返回满足回调函数条件的第一个元素的键</refpurpose> | ||
| </refnamediv> | ||
|
|
||
| <refsect1 role="description"> | ||
| &reftitle.description; | ||
| <methodsynopsis> | ||
| <type>mixed</type><methodname>array_find_key</methodname> | ||
| <methodparam><type>array</type><parameter>array</parameter></methodparam> | ||
| <methodparam><type>callable</type><parameter>callback</parameter></methodparam> | ||
| </methodsynopsis> | ||
| <simpara> | ||
| <function>array_find_key</function> 返回 &array; 中第一个使指定 <parameter>callback</parameter> 返回 &true; 的元素的键。如果未找到匹配元素,则该函数返回 &null;。 | ||
| </simpara> | ||
| </refsect1> | ||
|
|
||
| <refsect1 role="parameters"> | ||
| &reftitle.parameters; | ||
| <variablelist> | ||
| <varlistentry> | ||
| <term><parameter>array</parameter></term> | ||
| <listitem> | ||
| <simpara> | ||
| 需要被遍历的 &array;。 | ||
| </simpara> | ||
| </listitem> | ||
| </varlistentry> | ||
| <varlistentry> | ||
| <term><parameter>callback</parameter></term> | ||
| <listitem> | ||
| <para> | ||
| 用于检查每个元素的回调函数,该函数必须 | ||
| <methodsynopsis> | ||
| <type>bool</type><methodname><replaceable>callback</replaceable></methodname> | ||
| <methodparam><type>mixed</type><parameter>value</parameter></methodparam> | ||
| <methodparam><type>mixed</type><parameter>key</parameter></methodparam> | ||
| </methodsynopsis> | ||
| 如果该函数返回 &true;,<function>array_find_key</function> 就会返回对应键名,并且不再对后续元素执行该回调函数。 | ||
| </para> | ||
| </listitem> | ||
| </varlistentry> | ||
| </variablelist> | ||
| </refsect1> | ||
|
|
||
| <refsect1 role="returnvalues"> | ||
| &reftitle.returnvalues; | ||
| <simpara> | ||
| 该函数会返回首个使 <parameter>callback</parameter> 返回 &true; 的元素的键。如果未找到匹配的元素,则函数返回 &null;。 | ||
| </simpara> | ||
| </refsect1> | ||
|
|
||
| <refsect1 role="examples"> | ||
| &reftitle.examples; | ||
| <example> | ||
| <title><function>array_find_key</function></title> | ||
| <programlisting role="php"> | ||
| <![CDATA[ | ||
| <?php | ||
| $array = [ | ||
| 'a' => 'dog', | ||
| 'b' => 'cat', | ||
| 'c' => 'cow', | ||
| 'd' => 'duck', | ||
| 'e' => 'goose', | ||
| 'f' => 'elephant' | ||
| ]; | ||
|
|
||
| // Find the first animal with a name longer than 4 characters. | ||
| var_dump(array_find_key($array, function (string $value) { | ||
| return strlen($value) > 4; | ||
| })); | ||
|
|
||
| // Find the first animal whose name begins with f. | ||
| var_dump(array_find_key($array, function (string $value) { | ||
| return str_starts_with($value, 'f'); | ||
| })); | ||
|
|
||
| // Find the first animal where the array key is the first symbol of the animal. | ||
| var_dump(array_find_key($array, function (string $value, $key) { | ||
| return $value[0] === $key; | ||
| })); | ||
|
|
||
| // Find the first animal where the array key matching a RegEx. | ||
| var_dump(array_find_key($array, function ($value, $key) { | ||
| return preg_match('/^([a-f])$/', $key); | ||
| })); | ||
| ?> | ||
| ]]> | ||
| </programlisting> | ||
| &example.outputs; | ||
| <screen> | ||
| <![CDATA[ | ||
| string(1) "e" | ||
| NULL | ||
| string(1) "c" | ||
| string(1) "a" | ||
| ]]> | ||
| </screen> | ||
| </example> | ||
| </refsect1> | ||
|
|
||
| <refsect1 role="seealso"> | ||
| &reftitle.seealso; | ||
| <simplelist> | ||
| <member><function>array_find</function></member> | ||
| <member><function>array_all</function></member> | ||
| <member><function>array_any</function></member> | ||
| <member><function>array_filter</function></member> | ||
| <member><function>array_reduce</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 | ||
| --> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你是Maintainer,所以不需要加CREDITS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改