mirror of
https://github.com/php/doc-es.git
synced 2026-03-24 07:22:16 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@312323 c90b9560-bf6c-de11-be94-00142212c4b1
184 lines
4.9 KiB
XML
184 lines
4.9 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 9190379067d4cfae59c5234321b6bbdb71214784 Maintainer: yago Status: ready -->
|
|
<refentry xml:id="function.count" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>count</refname>
|
|
<refpurpose>Cuenta todos los elementos de un array o en un objecto</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>int</type><methodname>count</methodname>
|
|
<methodparam><type>mixed</type><parameter>var</parameter></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>mode</parameter><initializer>COUNT_NORMAL</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Cuenta todos los elementos en un array o en un objecto.
|
|
</para>
|
|
<para>
|
|
En objectos, si se tiene
|
|
<link linkend="ref.spl">SPL</link> instalado, se puede conectar a
|
|
<function>count</function> implementado el interfaz
|
|
<classname>Countable</classname>. Este interfaz tiene solamente un método,
|
|
<methodname>Countable::count</methodname>, el cual devuelve el valor retornado de la función
|
|
<function>count</function>.
|
|
</para>
|
|
<para>
|
|
Por favor ver la sección del manual <link linkend="language.types.array">Array</link>
|
|
para una explicación más extensa de como se implementan
|
|
y usan los arrays en PHP.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>var</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
El array o el objecto
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>mode</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Si el parámetro opcional <parameter>mode</parameter> está definido con la constante
|
|
<constant>COUNT_RECURSIVE</constant> (o 1), <function>count</function>
|
|
contará el array de forma recursiva. Esto es particularmente útil para
|
|
contar todos los elementos de un array multidimensional.
|
|
<function>count</function> no detecta recursión infinita.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Devuelve el número de elementos en <parameter>var</parameter>,
|
|
Si <parameter>var</parameter> no es un array o no es un objecto con el interfaz
|
|
<classname>Countable</classname> implementado,
|
|
devolverá <literal>1</literal>.
|
|
Existe una excepción, si <parameter>var</parameter> es &null;,
|
|
devolverá <literal>0</literal>.
|
|
</para>
|
|
<caution>
|
|
<para>
|
|
<function>count</function> devolverá 0 si la variable que se intenta contar no está definida
|
|
pero también devolverá 0 si la variable contiene un array
|
|
vacío. Use <function>isset</function> para comprobar si la variable está definida.
|
|
</para>
|
|
</caution>
|
|
</refsect1>
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<para>
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>4.2.0</entry>
|
|
<entry>
|
|
Se añadió el parámetro opcional <parameter>mode</parameter>.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo de <function>count</function></title>
|
|
<programlisting role="php">
|
|
<![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
|
|
|
|
$result = count(null);
|
|
// $result == 0
|
|
|
|
$result = count(false);
|
|
// $result == 1
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo de <function>count</function> recursivo</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$food = array('fruits' => array('orange', 'banana', 'apple'),
|
|
'veggie' => array('carrot', 'collard', 'pea'));
|
|
|
|
// Count recursivo
|
|
echo count($food, COUNT_RECURSIVE); // muestra 8
|
|
|
|
// Count normal
|
|
echo count($food); // muestra 2
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>is_array</function></member>
|
|
<member><function>isset</function></member>
|
|
<member><function>strlen</function></member>
|
|
</simplelist>
|
|
</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
|
|
-->
|