com doc/zh: 更新 is_scalar(): referen ce/var/functions/is-scalar.xml
| From: | Bole Chen | Date: | Sat, 20 Feb 2021 08:45:46 +0000 |
| Subject: | com doc/zh: 更新 is_scalar(): referen ce/var/functions/is-scalar.xml | ||
| Groups: | php.doc.zh | ||
| Request: | Send a blank email to doc-zh+get-5980@lists.php.net to get a copy of this message | ||
Commit: e387d5dc2b9a1c3c709b5c4df791957be362db82
Author: 蒋文健 <jwjbjg@gmail.com> Sat, 20 Feb 2021 16:13:07 +0800
Committer: Bole Chen <avenger@php.net> Sat, 20 Feb 2021 16:45:46 +0800
Parents: eed26fe52d5d014fff40b63f8bfe155a3a610bfb
Branches: master
Link: http://git.php.net/?p=doc/zh.git;a=commitdiff;h=e387d5dc2b9a1c3c709b5c4df791957be362db82
Log:
更新 is_scalar()
Close php/doc-zh#18
Bugs:
https://bugs.php.net/18
Changed paths:
M reference/var/functions/is-scalar.xml
Diff:
diff --git a/reference/var/functions/is-scalar.xml b/reference/var/functions/is-scalar.xml
index 9aa676b4..a692afd7 100644
--- a/reference/var/functions/is-scalar.xml
+++ b/reference/var/functions/is-scalar.xml
@@ -1,37 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- $Author$ -->
-<!-- EN-Revision: n/a Maintainer: nio Status: ready -->
-<!-- splitted from ./en/functions/var.xml, last change in rev 1.35 -->
- <refentry xml:id="function.is-scalar" xmlns="http://docbook.org/ns/docbook">
- <refnamediv>
- <refname>is_scalar</refname>
- <refpurpose>
+<!-- EN-Revision: 0c9c2dd669fe9395eaa73d487fbd160f9057429a Maintainer: nio Status: ready -->
+<refentry xml:id="function.is-scalar" xmlns="http://docbook.org/ns/docbook">
+ <refnamediv>
+ <refname>is_scalar</refname>
+ <refpurpose>
检测变量是否是一个标量
- </refpurpose>
- </refnamediv>
- <refsect1>
- <title>描述</title>
- <methodsynopsis>
- <type>bool</type><methodname>is_scalar</methodname>
-
<methodparam><type>mixed</type><parameter>var</parameter></methodparam>
- </methodsynopsis>
- <para>
- 如果给出的变量参数 <parameter>var</parameter>
是一个标量,<function>is_scalar</function>
- 返回 &true;,否则返回 &false;。
- </para>
- <para>
- 标量变量是指那些包含了
-
<type>integer</type>、<type>float</type>、<type>string</type>
- 或 <type>boolean</type>的变量,而
- <type>array</type>、<type>object</type> 和
<type>resource</type> 则不是标量。
- <informalexample>
- <programlisting role="php">
+ </refpurpose>
+ </refnamediv>
+
+ <refsect1 role="description">
+ &reftitle.description;
+ <methodsynopsis>
+ <type>bool</type><methodname>is_scalar</methodname>
+
<methodparam><type>mixed</type><parameter>value</parameter></methodparam>
+ </methodsynopsis>
+ <para>
+ 检测变量是否为标量
+ </para>
+ <para>
+ 标量变量是指 <type>int</type> 、 <type>float</type> 、
<type>string</type> 或 <type>bool</type> 类型的变量。
+ <type>array</type>、<type>object</type> 和
<type>resource</type> 类型不是标量。
+ </para>
+ <note>
+ <para>
+ <function>is_scalar</function> 不会将 <type>resource</type>
类型值视为标量,
+ 因为当前 resources 是基于整数(integer)的抽象数据类型。
+ 不能依赖该执行细节,因为它可能会改变。
+ </para>
+ </note>
+ <note>
+ <para>
+ <function>is_scalar</function> 不会将 NULL 检测为标量。
+ </para>
+ </note>
+ </refsect1>
+
+ <refsect1 role="parameters">
+ &reftitle.parameters;
+ <para>
+ <variablelist>
+ <varlistentry>
+ <term><parameter>value</parameter></term>
+ <listitem>
+ <para>
+ 需要检测的变量。
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </para>
+ </refsect1>
+
+ <refsect1 role="returnvalues">
+ &reftitle.returnvalues;
+ <para>
+ 如果 <parameter>value</parameter> 是标量,则返回 &true; ,否则返回
&false; 。
+ </para>
+ </refsect1>
+
+ <refsect1 role="examples">
+ &reftitle.examples;
+ <para>
+ <example>
+ <title><function>is_scalar</function> 示例</title>
+ <programlisting role="php">
<!-- TODO: better example, this one can be quite misleading for unexperienced
programmers. -->
<![CDATA[
<?php
-function show_var($var) {
+function show_var($var)
+{
if (is_scalar($var)) {
echo $var;
} else {
@@ -42,36 +82,45 @@ $pi = 3.1416;
$proteins = array("hemoglobin", "cytochrome c oxidase",
"ferredoxin");
show_var($pi);
-// 打印:3.1416
-
show_var($proteins)
-// 打印:
-// array(3) {
-// [0]=>
-// string(10) "hemoglobin"
-// [1]=>
-// string(20) "cytochrome c oxidase"
-// [2]=>
-// string(10) "ferredoxin"
-// }
+
?>
]]>
- </programlisting>
- </informalexample>
- </para>
- <note>
- <para>
- 尽管当前的 <type>resource</type> 类型是居于整数的,但
- <function>is_scalar</function>
不会把它们当作是标量,因为资源是抽象数据类型。不能依赖于执行细节,因为它可能会改变。
- </para>
- </note>
- <para>
- 参见
<function>is_bool</function>、<function>is_numeric</function>、<function>is_float</function>、<function>is_int</function>、<function>is_real</function>、<function>is_string</function>、<function>is_object</function>、<function>is_array</function>
- 和 <function>is_integer</function>。
- </para>
- </refsect1>
- </refentry>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+3.1416
+array(3) {
+ [0]=>
+ string(10) "hemoglobin"
+ [1]=>
+ string(20) "cytochrome c oxidase"
+ [2]=>
+ string(10) "ferredoxin"
+}
+]]>
+ </screen>
+ </example>
+ </para>
+ </refsect1>
+ <refsect1 role="seealso">
+ &reftitle.seealso;
+ <para>
+ <simplelist>
+ <member><function>is_float</function></member>
+ <member><function>is_int</function></member>
+ <member><function>is_numeric</function></member>
+ <member><function>is_real</function></member>
+ <member><function>is_string</function></member>
+ <member><function>is_bool</function></member>
+ <member><function>is_object</function></member>
+ <member><function>is_array</function></member>
+ </simplelist>
+ </para>
+ </refsect1>
+</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml