<?xml version="1.0" encoding="utf-8"?> <!-- $Revision$ --> <refentry xml:id="function.current" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>current</refname> <refpurpose>Return the current element in an array</refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <methodsynopsis> <type>mixed</type><methodname>current</methodname> <methodparam><type>array</type><parameter>array</parameter></methodparam> </methodsynopsis> <para> Every array has an internal pointer to its "current" element, which is initialized to the first element inserted into the array. </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>array</parameter></term> <listitem> <para> The array. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> The <function>current</function> function simply returns the value of the array element that's currently being pointed to by the internal pointer. It does not move the pointer in any way. If the internal pointer points beyond the end of the elements list or the array is empty, <function>current</function> returns &false;. </para> &return.falseproblem; </refsect1> <refsect1 role="changelog"> &reftitle.changelog; <para> <informaltable> <tgroup cols="2"> <thead> <row> <entry>&Version;</entry> <entry>&Description;</entry> </row> </thead> <tbody> <row> <entry>7.0.0</entry> <entry> <parameter>array</parameter> is now always passed by value. Prior to this version, it was passed by reference if possible, and by value otherwise. </entry> </row> </tbody> </tgroup> </informaltable> </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>Example use of <function>current</function> and friends</title> <programlisting role="php"> <![CDATA[ <?php $transport = array('foot', 'bike', 'car', 'plane'); $mode = current($transport); // $mode = 'foot'; $mode = next($transport); // $mode = 'bike'; $mode = current($transport); // $mode = 'bike'; $mode = prev($transport); // $mode = 'foot'; $mode = end($transport); // $mode = 'plane'; $mode = current($transport); // $mode = 'plane'; $arr = array(); var_dump(current($arr)); // bool(false) $arr = array(array()); var_dump(current($arr)); // array(0) { } ?> ]]> </programlisting> </example> </para> </refsect1> <refsect1 role="notes"> &reftitle.notes; <note> <simpara> The results of calling <function>current</function> on an empty array and on an array, whose internal pointer points beyond the end of the elements, are indistinguishable from a <type>boolean</type> &false; element. To properly traverse an array which may contain &false; elements, see the <function>foreach</function> function. </simpara> <simpara> To still use <function>current</function> and properly check if the value is really an element of the array, the <function>key</function> of the <function>current</function> element should be checked to be strictly different from &null;. </simpara> </note> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><function>end</function></member> <member><function>key</function></member> <member><function>each</function></member> <member><function>prev</function></member> <member><function>reset</function></member> <member><function>next</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 -->