mirror of
https://github.com/php/doc-es.git
synced 2026-03-25 07:52:21 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@172353 c90b9560-bf6c-de11-be94-00142212c4b1
147 lines
4.5 KiB
XML
147 lines
4.5 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.4 $ -->
|
|
<!-- EN-Revision: 1.15 Maintainer: baoengb Status: ready -->
|
|
<!-- splitted from ./es/functions/array.xml, last change in rev 1.1 -->
|
|
<refentry id="function.count">
|
|
<refnamediv>
|
|
<refname>count</refname>
|
|
<refpurpose>Cuenta los elementos de una matriz o propiedades de un objeto
|
|
</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Descripción</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>
|
|
Devuelve el número de elementos en <parameter>var</parameter>,
|
|
que típicamente es una matriz, porque cualquier otra cosa diferente
|
|
de un objeto tendría sólo un elemento.
|
|
</para>
|
|
<para>
|
|
Para objetos <function>count</function> regresará el número
|
|
de propiedades no estáticas, sin tomar en cuenta su visibilidad.
|
|
Si tiene instalado <link linkend="ref.spl">SPL</link>, enlazarlo a
|
|
<function>count</function> implementando la interface
|
|
<literal>Countable</literal>. La interface tiene exactamente un
|
|
método, <function>count</function>, el cual regresa el mismo valor
|
|
que regresarí la función <function>count</function>.
|
|
</para>
|
|
<para>
|
|
Si <parameter>var</parameter> no es una matriz o un objeto,
|
|
se regresará <literal>1</literal>. Hay una excepción,
|
|
si <parameter>var</parameter> es &null;, se regresará
|
|
<literal>0</literal>.
|
|
</para>
|
|
<note>
|
|
<simpara>
|
|
El parámetro opcional <parameter>mode</parameter> está
|
|
disponible desde PHP 4.2.0.
|
|
</simpara>
|
|
</note>
|
|
<para>
|
|
Si el parámetro opcional <parameter>mode</parameter> es iniciado a
|
|
<constant>COUNT_RECURSIVE</constant> (o 1), <function>count</function>
|
|
contará recursivamente la matriz. Esto es útil particularmente
|
|
para contar todos los elementos de una matriz multidimensional. El valor
|
|
por defecto para <parameter>mode</parameter> es <literal>0</literal>.
|
|
<function>count</function> no detecta recursión infinita.
|
|
</para>
|
|
<caution>
|
|
<para>
|
|
<function>count</function> puede regresar 0 para una variable que no
|
|
ha sido inicializada, pero también regresa 0 para una variable
|
|
que ha sido inicializada con una matriz vacía. Use
|
|
<function>isset</function> para probar si la variable ha sido definida.
|
|
</para>
|
|
</caution>
|
|
<para>
|
|
Por favor vea la sección del manual sobre
|
|
<link linkend="language.types.array">Array</link> para una explicación
|
|
más detallada de como son usadas e implementadas las matrices en PHP.
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo</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;
|
|
|
|
$obj = new StdClass;
|
|
$obj->foo = 'A property';
|
|
$obj->bar = 'Another property';
|
|
$result = count($obj);
|
|
// $result == 2;
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo recursivo (PHP >= 4.2.0)</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$food = array('fruits' => array('orange', 'banana', 'apple'),
|
|
'veggie' => array('carrot', 'collard', 'pea'));
|
|
|
|
// recursive count
|
|
echo count($food, COUNT_RECURSIVE); // output 8
|
|
|
|
// normal count
|
|
echo count($food); // output 2
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
Vea también <function>is_array</function>,
|
|
<function>isset</function>, and
|
|
<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
|
|
-->
|