mirror of
https://github.com/php/doc-ja.git
synced 2026-03-25 15:42:08 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/ja/trunk@327506 c90b9560-bf6c-de11-be94-00142212c4b1
235 lines
6.6 KiB
XML
235 lines
6.6 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: d6b4563c0825092ca3e13700d76a34f527e8ba53 Maintainer: takagi Status: ready -->
|
|
<!-- CREDITS: hirokawa,shimooka -->
|
|
<refentry xml:id="function.sort" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<refnamediv>
|
|
<refname>sort</refname>
|
|
<refpurpose>配列をソートする</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>bool</type><methodname>sort</methodname>
|
|
<methodparam><type>array</type><parameter role="reference">array</parameter></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>sort_flags</parameter><initializer>SORT_REGULAR</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
この関数は配列をソートします。この関数が正常に終了すると、
|
|
各要素が小さい順に並び変わった状態になります。
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>array</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
入力の配列。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>sort_flags</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
オプションの 2 番目のパラメータ <parameter>sort_flags</parameter>
|
|
は、以下の値によりソートの動作を修正するために使用することが可能です。
|
|
</para>
|
|
<para>
|
|
ソート型のフラグ:
|
|
<itemizedlist>
|
|
<listitem>
|
|
<simpara><constant>SORT_REGULAR</constant> - 通常通りに項目を比較
|
|
(型は変更しません)</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara><constant>SORT_NUMERIC</constant> - 数値的に項目を比較</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara><constant>SORT_STRING</constant> - 文字列として項目を比較</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<constant>SORT_LOCALE_STRING</constant> - は、現在のロケールに基づいて比較します。
|
|
比較に使うロケールは、<function>setlocale</function> で変更できます。
|
|
<!-- FIXME PHP_6
|
|
PHP 6 より前のバージョンではシステムロケールを使用します。これは
|
|
<function>setlocale</function> を使用して変更可能です。
|
|
PHP 6 以降では、<function>i18n_loc_set_default</function> 関数を
|
|
使用する必要があります。
|
|
-->
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<constant>SORT_NATURAL</constant> - 要素の比較を文字列として行い、
|
|
<function>natsort</function> と同様の「自然順」で比較します。
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<constant>SORT_FLAG_CASE</constant> -
|
|
<constant>SORT_STRING</constant> や
|
|
<constant>SORT_NATURAL</constant> と (ビット OR で) 組み合わせて使い、
|
|
文字列のソートで大文字小文字を区別しないようにします。
|
|
</simpara>
|
|
</listitem>
|
|
</itemizedlist>
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
&return.success;
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>5.4.0</entry>
|
|
<entry>
|
|
<parameter>sort_flags</parameter> に
|
|
<constant>SORT_NATURAL</constant> と
|
|
<constant>SORT_FLAG_CASE</constant> が使えるようになりました。
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>5.0.2</entry>
|
|
<entry>
|
|
<constant>SORT_LOCALE_STRING</constant> が追加されました。
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</refsect1>
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title><function>sort</function> の例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$fruits = array("lemon", "orange", "banana", "apple");
|
|
sort($fruits);
|
|
foreach ($fruits as $key => $val) {
|
|
echo "fruits[" . $key . "] = " . $val . "\n";
|
|
}
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
fruits[0] = apple
|
|
fruits[1] = banana
|
|
fruits[2] = lemon
|
|
fruits[3] = orange
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
fruits はアルファベットの昇順にソートされました。
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title><function>sort</function> で、大文字小文字を区別せずに自然順での並べ替えを行う例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$fruits = array(
|
|
"Orange1", "orange2", "Orange3", "orange20"
|
|
);
|
|
sort($fruits, SORT_NATURAL | SORT_FLAG_CASE);
|
|
foreach ($fruits as $key => $val) {
|
|
echo "fruits[" . $key . "] = " . $val . "\n";
|
|
}
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
fruits[0] = Orange1
|
|
fruits[1] = orange2
|
|
fruits[2] = Orange3
|
|
fruits[3] = orange20
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
fruits が <function>natcasesort</function> と同じようにソートされました。
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
¬e.no-key-association;
|
|
<note>
|
|
<simpara>
|
|
PHP の大半のソート関数と同様、<function>sort</function> は
|
|
<link xlink:href="&url.wiki.quicksort;">Quicksort</link>
|
|
でそれを実装しています。
|
|
</simpara>
|
|
</note>
|
|
<warning>
|
|
<simpara>
|
|
複数の型が混在する配列をソートする場合には、注意してください。
|
|
<function>sort</function> が予測不可能な結果を出力することがあります。
|
|
</simpara>
|
|
</warning>
|
|
</refsect1>
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>asort</function></member>
|
|
<member>&seealso.array.sorting;</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
|
|
-->
|