1
0
mirror of https://github.com/php/doc-uk.git synced 2026-03-25 15:42:11 +01:00
Files
2024-09-04 19:33:54 +03:00

172 lines
5.6 KiB
XML
Raw Permalink 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: d58ee8eaaa7f716c51f66f5f1058ab3c42376d98 Maintainer: mproshchuk Status: ready -->
<refentry xml:id="function.compact" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>compact</refname>
<refpurpose>Створює масив, який містить назви змінних та їхні значення</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>array</type><methodname>compact</methodname>
<methodparam><type class="union"><type>array</type><type>string</type></type><parameter>var_name</parameter></methodparam>
<methodparam rep="repeat"><type class="union"><type>array</type><type>string</type></type><parameter>var_names</parameter></methodparam>
</methodsynopsis>
<para>
Створює масив, який містить назви змінних та їх значення.
</para>
<para>
Для кожного з переданих параметрів функція <function>compact</function>
шукає змінну в поточній <link
linkend="features.gc.refcounting-basics">таблиці</link> символів та додає її
до вихідного масиву таким чином, що назва змінної стає ключем елемента
масиву, а її значення — значенням цього елемента. Коротше кажучи — це повна
протилежність до <function>extract</function>.
</para>
<note>
<para>
До PHP 7.3, будь-які невстановлені рядки будуть просто пропущені.
</para>
</note>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>var_name</parameter></term>
<term><parameter>var_names</parameter></term>
<listitem>
<para>
<function>compact</function> приймає безліч параметрів. Кожен параметр
може бути рядком, що містить назву змінної, або масивом назв змінних.
Масив може містити інші масиви назв змінних; функція
<function>compact</function> опрацьовує їх рекурсивно.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Повертає вихідний масив усіх змінних, які були додані у нього.
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
Якщо заданий рядок посилається на невизначену змінну,
<function>compact</function> видає помилку рівня
<constant>E_WARNING</constant>.
</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>
Тепер видається помилка рівня <constant>E_WARNING</constant>, якщо
заданий рядок посилається на невизначену змінну.
</entry>
</row>
<row>
<entry>7.3.0</entry>
<entry>
<function>compact</function> тепер видає помилку рівня
<constant>E_NOTICE</constant>, якщо заданий рядок посилається на
невизначену змінну. Раніше такі рядки просто пропускалися.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1><!-- }}} -->
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Використання <function>compact</function></title>
<programlisting role="php">
<![CDATA[
<?php
$city = "Сан-Франциско";
$state = "CA";
$event = "SIGGRAPH";
$location_vars = array("city", "state");
$result = compact("event", $location_vars);
print_r($result);
?>
]]>
</programlisting>
&example.outputs;
<screen role="php">
<![CDATA[
Array
(
[event] => SIGGRAPH
[city] => Сан-Франциско
[state] => CA
)
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<note>
<title>Gotcha</title>
<para>
Оскільки <link linkend="language.variables.variable">змінні змінних</link>
не можуть бути використані разом з суперглобальним масивом <link
linkend="language.variables.superglobals"></link> в межах функцій,
суперглобальні масиви не можуть бути передані в <function>compact</function>.
</para>
</note>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>extract</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
-->