1
0
mirror of https://github.com/php/doc-ja.git synced 2026-04-24 00:18:15 +02:00
Files
archived-doc-ja/reference/array/functions/count.xml
T
Rui Hirokawa a082536353 translated sync tag into En-Revision.
git-svn-id: https://svn.php.net/repository/phpdoc/ja/trunk@173330 c90b9560-bf6c-de11-be94-00142212c4b1
2004-11-23 04:34:59 +00:00

128 lines
3.9 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 1.5 $ -->
<!-- EN-Revision: 1.11 Maintainer: hirokawa Status: ready -->
<refentry id="function.count">
<refnamediv>
<refname>count</refname>
<refpurpose>変数に含まれる要素の数を数える</refpurpose>
</refnamediv>
<refsect1>
<title>説明</title>
<methodsynopsis>
<type>int</type><methodname>count</methodname>
<methodparam><type>mixed</type><parameter>var</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>mode</parameter></methodparam>
</methodsynopsis>
<para>
<parameter>var</parameter>に含まれる要素の数を返します。
通常、<parameter>var</parameter>は配列です(他のものには、1つの要素しか
ありませんから)。
</para>
<para>
変数が配列でない場合は<literal>1</literal>を返します。
(例外: <literal>count(&null;)</literal><literal>0</literal>と等価)
</para>
<note>
<simpara>
オプションの<parameter>mode</parameter>引数はPHP 4.2.0 以降で使用可能です。
</simpara>
</note>
<para>
オプションの<parameter>mode</parameter>引数が<constant>COUNT_RECURSIVE</constant>
(または1)にセットされた場合、<function>count</function>は再帰的に
配列をカウントします。これは多次元配列の全ての要素をカウントするといった
場合に特に有効です。<parameter>mode</parameter>のデフォルトは
<literal>0</literal>です。
</para>
<caution>
<para>
<function>count</function>は、セットされていない変数に関して0を返
しますが、変数が空の配列として初期化されている場合にも0を返します。
ある変数がセットされているかどうかを調べるには、
<function>isset</function>を使用してください。
</para>
</caution>
<para>
配列の実装やPHPでの使用法に関する詳細な説明についてはマニュアルの
<link linkend="language.types.array">配列</link>のセクションを
参照下さい。
</para>
<para>
<example>
<title><function>count</function> の例</title>
<programlisting role="php">
<!-- TODO: examples about count(null), count(false), count(object).. -->
<![CDATA[
<?php
$a[0] = 1;
$a[1] = 3;
$a[2] = 5;
$result = count ($a);
// $result == 3
$b[0] = 7;
$b[5] = 9;
$b[10] = 11;
$result = count ($b);
// $result == 3;
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title>
recursive <function>count</function>の例 (PHP &gt;= 4.2.0)
</title>
<programlisting role="php">
<![CDATA[
<?php
$food = array('fruits' => array('orange', 'banana', 'apple'),
'veggie' => array('carrot', 'collard', 'pea'));
// 再帰的なカウント
echo count($food, COUNT_RECURSIVE); // output 8
// 通常のカウント
echo count($food); // output 2
?>
]]>
</programlisting>
</example>
</para>
<note>
<para>
<function>sizeof</function>関数は、<function>count</function>
への<link linkend="aliases">エイリアス</link>です。
</para>
</note>
<para>
<function>is_array</function>, <function>isset</function>,
<function>strlen</function>も参照下さい。
</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:"../../../../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
-->