mirror of
https://github.com/php/doc-es.git
synced 2026-03-26 00:12:06 +01:00
- All id attributes are now xml:id - Add docbook namespace to all root elements - Replace <ulink /> with <link xlink:href /> - Minor markup fixes here and there - Bump EN-Revision where appropriate git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@238324 c90b9560-bf6c-de11-be94-00142212c4b1
171 lines
5.0 KiB
XML
171 lines
5.0 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.4 $ -->
|
|
<!-- EN-Revision: 1.13 Maintainer: baoengb Status: ready -->
|
|
<!-- splitted from ./es/functions/array.xml, last change in rev 1.1 -->
|
|
<refentry xml:id="function.array" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>array</refname>
|
|
<refpurpose>
|
|
Crear una matriz
|
|
</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Descripción</title>
|
|
<methodsynopsis>
|
|
<type>array</type><methodname>array</methodname>
|
|
<methodparam rep="repeat"><type>mixed</type><parameter>...</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Devuelve una matriz con los parámetros que se le pasan. A dichos
|
|
parámetros se les puede dar un índice usando el operador
|
|
<literal>=></literal>. Lea la sección sobre los
|
|
<link linkend="language.types.array">tipos de matrices</link> para más
|
|
información sobre matrices.
|
|
<note>
|
|
<para>
|
|
<function>array</function> es una construcción del lenguaje que se
|
|
utiliza para representar matrices literales, no una función regular.
|
|
</para>
|
|
</note>
|
|
</para>
|
|
<para>
|
|
La forma "índice => valor" separada por comas, define índices
|
|
y valores. el índice puede ser de tipo cadena o numérico.
|
|
Cuando el índice es omitido, se genera automáticamente un
|
|
índice numérico, empezando en cero. Si el índice es
|
|
un entero, el siguiente índice generado será igual al índice
|
|
con número mayor + 1. Note que cuando se definen dos índices
|
|
idénticos, el último sobre escribe al primero.
|
|
</para>
|
|
<para>
|
|
Tener una coma después del último elemento de la matriz, aunque
|
|
inusual, es sintácticamente valido.
|
|
</para>
|
|
<para>
|
|
El siguiente ejemplo demuestra cómo crear una matriz
|
|
bidimensional, cómo especificar claves para matrices
|
|
asociativas, y cómo especificar índices no consecutivos
|
|
en matrices normales.
|
|
<example>
|
|
<title>Ejemplo de <function>array</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$frutas = array (
|
|
"frutas" => array("a"=>"naranja", "b"=>"plátano", "c"=>"manzana"),
|
|
"números" => array(1, 2, 3, 4, 5, 6),
|
|
"hoyos" => array("primero", 5 => "segundo", "tercero")
|
|
);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Índice automático con <function>array</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$array = array(1, 1, 1, 1, 1, 8 => 1, 4 => 1, 19, 3 => 13);
|
|
print_r($array);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen role="php">
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[0] => 1
|
|
[1] => 1
|
|
[2] => 1
|
|
[3] => 13
|
|
[4] => 1
|
|
[8] => 1
|
|
[9] => 19
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
Note que el índice '3' es definido dos veces, y permanece su valor
|
|
final de '13'. El índice 4 es definido depués del índice
|
|
8, y en seguida se genera el índice 9 (para el valor 19), porque
|
|
el índice mayor era 8.
|
|
</para>
|
|
<para>
|
|
Este ejemplo crea una matriz en donde los índices inician en 1.
|
|
<example>
|
|
<title>Índice base 1 con <function>array</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$primercuarto = array(1 => 'Enero', 'Febrero', 'Marzo');
|
|
print_r($primercuarto);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[1] => Enero
|
|
[2] => Febrero
|
|
[3] => Marzo
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
Como en Perl, puede accesar un valor de la matriz desde dentro de una
|
|
cadena contenida en dobles comillas. Sin embargo, con PHP necesitará
|
|
encerrar la matriz entre las llaves curvas.
|
|
<example>
|
|
<title>Accesando una matriz dentro de una cadena</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$foo = array('bar' => 'baz');
|
|
echo "Hello {$foo['bar']}!"; // Hello baz!
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
Vea también <function>array_pad</function>,
|
|
<function>list</function>,
|
|
<function>count</function>,
|
|
<link linkend="control-structures.foreach">foreach</link>,
|
|
<function>range</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
|
|
-->
|