1
0
mirror of https://github.com/php/doc-es.git synced 2026-03-24 15:32:36 +01:00
Files
archived-doc-es/reference/array/functions/array-fill.xml
2025-06-28 23:32:30 +02:00

220 lines
5.3 KiB
XML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 2e60c5134e7a847c99f81eb3f7ecee1f5efeeace Maintainer: PhilDaiguille Status: ready -->
<!-- Reviewed: no -->
<refentry xml:id="function.array-fill" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>array_fill</refname>
<refpurpose>Rellena un array con un mismo valor</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>array</type><methodname>array_fill</methodname>
<methodparam><type>int</type><parameter>start_index</parameter></methodparam>
<methodparam><type>int</type><parameter>count</parameter></methodparam>
<methodparam><type>mixed</type><parameter>value</parameter></methodparam>
</methodsynopsis>
<para>
Crea un array con <parameter>count</parameter> entradas, todas con el valor
<parameter>value</parameter>. Los índices comienzan con el valor
<parameter>start_index</parameter>.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>start_index</parameter></term>
<listitem>
<para>
El primer índice del array devuelto.
</para>
<para>
Si <parameter>start_index</parameter> es negativo,
el primer índice del array devuelto será
<parameter>start_index</parameter>, seguido por índices comenzando en
cero en versiones anteriores a PHP 8.0.0;
a partir de PHP 8.0.0, los índices negativos se incrementan normalmente.
(ver el '<link linkend="function.array-fill.example.negative-start-index">ejemplo</link>).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>count</parameter></term>
<listitem>
<para>
Número de elementos a insertar.
Debe ser superior o igual a cero, e inferior o igual a <literal>2147483647</literal>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>value</parameter></term>
<listitem>
<para>
Valor a utilizar para rellenar el array
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Devuelve el array rellenado.
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
Lanza una excepción <classname>ValueError</classname> si
<parameter>count</parameter> está fuera del rango permitido.
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.0.0</entry>
<entry>
La función <function>array_fill</function> lanza ahora una <classname>ValueError</classname>
si <parameter>count</parameter> está fuera del rango permitido;
anteriormente se emitía una advertencia de nivel <constant>E_WARNING</constant> y la función devolvía &false;.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example xml:id="function.array-fill.example.basic">
<title>Ejemplo con <function>array_fill</function></title>
<programlisting role="php">
<![CDATA[
<?php
$a = array_fill(5, 6, 'banana');
print_r($a);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Array
(
[5] => banana
[6] => banana
[7] => banana
[8] => banana
[9] => banana
[10] => banana
)
]]>
</screen>
</example>
</para>
<para>
<example xml:id="function.array-fill.example.negative-start-index">
<title>Ejemplo de <function>array_fill</function> con un índice de inicio negativo</title>
<programlisting role="php">
<![CDATA[
<?php
$a = array_fill(-2, 4, 'pear');
print_r($a);
?>
]]>
</programlisting>
&example.outputs.8;
<screen>
<![CDATA[
Array
(
[-2] => pear
[-1] => pear
[0] => pear
[1] => pear
)
]]>
</screen>
&example.outputs.7;
<screen>
<![CDATA[
Array
(
[-2] => pear
[0] => pear
[1] => pear
[2] => pear
)
]]>
</screen>
</example>
</para>
<para>
Observe que el índice <literal>-1</literal> no estaba presente antes de PHP 8.0.0.
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<para>
Ver también la sección del manual sobre los
<link linkend="language.types.array">arrays</link>
para más información sobre las claves negativas.
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>array_fill_keys</function></member>
<member><function>str_repeat</function></member>
<member><function>range</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
-->