mirror of
https://github.com/php/doc-it.git
synced 2026-03-24 15:42:46 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/it/trunk@314534 c90b9560-bf6c-de11-be94-00142212c4b1
143 lines
4.3 KiB
XML
143 lines
4.3 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!-- splitted from ./it/functions/array.xml, last change in rev 1.1 -->
|
|
<!-- last change to 'count' in en/ tree in rev 1.2 -->
|
|
<!-- EN-Revision: n/a Maintainer: cucinato Status: ready -->
|
|
<!-- OLD-Revision: 1.173/EN.1.2 -->
|
|
<refentry xml:id="function.count" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>count</refname>
|
|
<refpurpose>Conta gli elementi in una variabile, o le proprietà in un oggetto</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Descrizione</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>
|
|
Restituisce il numero di elementi in <parameter>var</parameter>,
|
|
la quale è di norma un <type>array</type>, dal momento che qualsiasi altro oggetto
|
|
avrà un elemento.
|
|
</para>
|
|
<para>
|
|
Per gli oggetti, se
|
|
<link linkend="ref.spl">SPL</link> è installato, è possibile agganciarsi a
|
|
<function>count</function> implementando l'interfaccia
|
|
<literal>Countable</literal>. L'interfaccia ha esattamente un metodo,
|
|
<function>count</function>, che ritorna il valore restituito dalla
|
|
funzione <function>count</function>.
|
|
</para>
|
|
<para>
|
|
Se <parameter>var</parameter> non è un array o un oggetto con
|
|
l'interfaccia <literal>Countable</literal> implementata,
|
|
verrà restituito <literal>1</literal>
|
|
C'è una eccezione, se <parameter>var</parameter> è &null;,
|
|
verrà restituito <literal>0</literal>.
|
|
</para>
|
|
<note>
|
|
<simpara>
|
|
Il parametro opzionale <parameter>mode</parameter> è disponibile da
|
|
PHP 4.2.0.
|
|
</simpara>
|
|
</note>
|
|
<para>
|
|
Se il parametro opzionale <parameter>mode</parameter> è impostato a
|
|
<constant>COUNT_RECURSIVE</constant> (o 1), <function>count</function>
|
|
conterà ricorsivamente l'array. Questo è utile in particolare per
|
|
contare tutti gli elementi di un array multidimensionale. Il valore di
|
|
default per <parameter>mode</parameter> è <literal>0</literal>.
|
|
<function>count</function> non identifica le ricorsioni infinite.
|
|
</para>
|
|
<caution>
|
|
<para>
|
|
<function>count</function> può restituire 0 per una variabile che
|
|
non è impostata, ma può anche restituire 0 per una variabile che è
|
|
stata inizializzata con un array vuoto. Usare
|
|
<function>isset</function> per verificare se una variabile è impostata.
|
|
</para>
|
|
</caution>
|
|
<para>
|
|
Vedere la sezione <link linkend="language.types.array">Array</link>
|
|
nel manuale per una spiegazione dettagliata di come gli array siano
|
|
implementati ed usati in PHP.
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>esempio di <function>count</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$a[0] = 1;
|
|
$a[1] = 3;
|
|
$a[2] = 5;
|
|
$risultato = count($a);
|
|
//$risultato == 3
|
|
|
|
$b[0] = 7;
|
|
$b[5] = 9;
|
|
$b[10] = 11;
|
|
$risultato = count($b);
|
|
// $risultato == 3;
|
|
|
|
$result = count(null);
|
|
// $result == 0
|
|
|
|
$result = count(false);
|
|
// $result == 1
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>
|
|
esempio di <function>count</function> ricorsiva (PHP >= 4.2.0)
|
|
</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$cibo = array('frutta' => array('arancia', 'banana', 'mela'),
|
|
'verdura' => array('carota', 'zucchina', 'piselli'));
|
|
|
|
// conteggio ricorsivo
|
|
echo count($cibp,COUNT_RECURSIVE); // output 8
|
|
|
|
// conteggio normale
|
|
echo count($cibo); // output 2
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
Vedere anche <function>is_array</function>,
|
|
<function>isset</function> e
|
|
<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:"~/.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
|
|
-->
|