mirror of
https://github.com/php/doc-es.git
synced 2026-03-26 08:22:08 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@338335 c90b9560-bf6c-de11-be94-00142212c4b1
166 lines
5.4 KiB
XML
166 lines
5.4 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 714db5b24b5b9e3bb9f3a33dba2408eec52a7f99 Maintainer: seros Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.max">
|
|
<refnamediv>
|
|
<refname>max</refname>
|
|
<refpurpose>Encontrar el valor más alto</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>mixed</type><methodname>max</methodname>
|
|
<methodparam><type>array</type><parameter>values</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<methodsynopsis>
|
|
<type>mixed</type><methodname>max</methodname>
|
|
<methodparam><type>mixed</type><parameter>value1</parameter></methodparam>
|
|
<methodparam><type>mixed</type><parameter>value2</parameter></methodparam>
|
|
<methodparam choice="opt"><type>mixed</type><parameter>...</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Si el primer y único parámetro es un array, <function>max</function>
|
|
devuelve el valor más alto de ese array. Si se proporcionan al menos dos
|
|
parámetros, <function>max</function> devuelve el mayor de estos valores.
|
|
</para>
|
|
<note>
|
|
<para>
|
|
Valores de diferentes tipos serán comparados utilizando las <link linkend="language.operators.comparison">
|
|
reglas de comparación estándar</link>. Por ejemplo, un <type>string</type> no numérico será
|
|
comparado con un <type>integer</type> como si fuera <literal>0</literal>, aunque varios
|
|
valores de tipo <type>string</type> serán comparados alfanuméricamente. El valor real devuelto será del
|
|
tipo original sin ninguna conversión aplicada.
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>values</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Un array que contiene los valores.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>value1</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Cualquier valor
|
|
<link linkend="language.operators.comparison">comparable</link>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>value2</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Cualquier valor
|
|
<link linkend="language.operators.comparison">comparable</link>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>...</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Cualquier valor
|
|
<link linkend="language.operators.comparison">comparable</link>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
<function>max</function> devuelve el valor del parámetro condierado "el mayor" según la comparación
|
|
estándar. Si varios valores de diferentes tipos se evalúan como iguales (p.ej. <literal>0</literal>
|
|
y <literal>'abc'</literal>), será devuelto el primero proporcionado a la función.
|
|
</para>
|
|
|
|
<para>
|
|
Si se pasa un array vacío, se devolverá &false; y se
|
|
emitirá un error <constant>E_WARNING</constant>.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Ejemplos de uso de <function>max</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
echo max(2, 3, 1, 6, 7); // 7
|
|
echo max(array(2, 4, 5)); // 5
|
|
|
|
// La cadena 'hola' es tratada como 0 cuando se compara con un número entero
|
|
// Ya que los dos valores son iguales, el orden en el que se proporcionan determina el resultado
|
|
echo max(0, 'hola'); // 0
|
|
echo max('hola', 0); // hola
|
|
|
|
// Aquí se compara -1 < 0, por lo que 'hola' es el valor mayor
|
|
echo max(-1, 'hola'); // hola
|
|
|
|
// Con varios arrays de diferentes longitudes, max devuelve el más largo
|
|
$val = max(array(2, 2, 2), array(1, 1, 1, 1)); // array(1, 1, 1, 1)
|
|
|
|
// Varios arrays de la misma longitud son comparados de izquierda a derecha,
|
|
// así que en nuestro ejemplo: 2 == 2, pero 5 > 4
|
|
$val = max(array(2, 4, 8), array(2, 5, 1)); // array(2, 5, 1)
|
|
|
|
// Si se pasan un array y algo que no sea un array, el array nunca es devuelto
|
|
// ya que las comparaciones tratan a los arrays como mayores que cualquier otro valor
|
|
$val = max('cadena', array(2, 5, 7), 42); // array(2, 5, 7)
|
|
|
|
// Si un argumento es NULL o un booleano, será comparado con
|
|
// otros valores usando la regla FALSE < TRUE independientemente de los otros tipos involucrados
|
|
// En los ejemplos de abajo, -10 y 10 son tratados como TRUE en la comparación
|
|
$val = max(-10, FALSE); // -10
|
|
|
|
// 0, por el contrario, es tratado como FALSE, por lo que es "menor que" TRUE
|
|
$val = max(0, TRUE); // TRUE
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>min</function></member>
|
|
<member><function>count</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
|
|
-->
|