Files
php-doc-ru/reference/array/functions/array-replace.xml
Alexey Pyltsyn 2b3cca3b0a Array Functions: improvements
git-svn-id: https://svn.php.net/repository/phpdoc/ru/trunk@344161 c90b9560-bf6c-de11-be94-00142212c4b1
2018-02-02 07:02:28 +00:00

137 lines
4.8 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. 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: bfee3967e880f7951b1d68f2c9948715d573b3e7 Maintainer: tmn Status: ready -->
<!-- Reviewed: yes -->
<!-- $Revision$ -->
<refentry xml:id="function.array-replace" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>array_replace</refname>
<refpurpose>Заменяет элементы массива элементами других переданных массивов</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>array</type><methodname>array_replace</methodname>
<methodparam><type>array</type><parameter>array1</parameter></methodparam>
<methodparam><type>array</type><parameter>array2</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>...</parameter></methodparam>
</methodsynopsis>
<para>
<function>array_replace</function> замещает значения массива
<parameter>array1</parameter> значениями с такими же ключами из
других переданных массивов. Если ключ из первого массива присутствует
во втором массиве, его значение заменяется на значение из второго массива.
Если ключ есть во втором массиве, но отсутствует в первом - он будет создан
в первом массиве. Если ключ присутствует только в первом массиве, то
сохранится как есть. Если для замены передано несколько массивов, они
будут обработаны в порядке передачи и последующие массивы будут
перезаписывать значения из предыдущих.
</para>
<para>
<function>array_replace</function> не рекурсивная: значения первого массива
будут заменены вне зависимости от типа значений второго массива, даже если
это будут вложенные массивы.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>array1</parameter></term>
<listitem>
<para>
Массив, элементы которого требуется заменить.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>array2</parameter></term>
<listitem>
<para>
Массив, элементами которого будут заменяться элементы первого массива.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>...</parameter></term>
<listitem>
<para>
Еще массивы, из которых будут браться элементы для замены.
Значения следующего массива затирают значения предыдущего.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Возвращает массив (<type>array</type>) или &null; в случае ошибки.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Пример использования <function>array_replace</function></title>
<programlisting role="php">
<![CDATA[
<?php
$base = array("orange", "banana", "apple", "raspberry");
$replacements = array(0 => "pineapple", 4 => "cherry");
$replacements2 = array(0 => "grape");
$basket = array_replace($base, $replacements, $replacements2);
print_r($basket);
?>
]]>
</programlisting>
&example.outputs;
<screen role="php">
<![CDATA[
Array
(
[0] => grape
[1] => banana
[2] => apple
[3] => raspberry
[4] => cherry
)
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>array_replace_recursive</function></member>
<member><function>array_merge</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
-->