cvs: phpdoc-ja /reference/array/functions array-multisort.xml

From: Date: Sun, 07 Aug 2005 06:30:23 +0000
Subject: cvs: phpdoc-ja /reference/array/functions array-multisort.xml
Groups: php.doc.ja 
Request: Send a blank email to doc-ja+get-1109@lists.php.net to get a copy of this message
takagi Sun Aug 7 02:30:23 2005 EDT Modified files: /phpdoc-ja/reference/array/functions array-multisort.xml Log: sync with en. http://cvs.php.net/diff.php/phpdoc-ja/reference/array/functions/array-multisort.xml?r1=1.5&r2=1.6&ty=u Index: phpdoc-ja/reference/array/functions/array-multisort.xml diff -u phpdoc-ja/reference/array/functions/array-multisort.xml:1.5 phpdoc-ja/reference/array/functions/array-multisort.xml:1.6 --- phpdoc-ja/reference/array/functions/array-multisort.xml:1.5 Wed Dec 15 11:00:27 2004 +++ phpdoc-ja/reference/array/functions/array-multisort.xml Sun Aug 7 02:30:22 2005 @@ -1,5 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> -<!-- EN-Revision: 1.13 Maintainer: hirokawa Status: working --> +<!-- $Revision: 1.6 $ --> +<!-- EN-Revision: 1.17 Maintainer: hirokawa Status: ready --> +<!-- CREDITS: takagi --> <refentry id="function.array-multisort"> <refnamediv> <refname>array_multisort</refname> @@ -115,31 +117,37 @@ <programlisting role="php"> <![CDATA[ <?php -$ar = array (array ("10", 100, 100, "a"), array (1, 3, "2", 1)); +$ar = array( + array("10", 11, 100, 100, "a"), + array( 1, 2, "2", 3, 1) + ); array_multisort ($ar[0], SORT_ASC, SORT_STRING, $ar[1], SORT_NUMERIC, SORT_DESC); +var_dump($ar); ?> ]]> </programlisting> <para> - この例では、ソートされた後、最初の配列は10,100, 100, "a" (文字列 - として昇順でソートされています)を有しており、2番目の配列は、 - 1, 3, "2", 1 (数値として降順にソートされています)となっています。 + この例では、ソートされた後、最初の配列は "10", 100, 100, 11, "a" (文字列 + として昇順でソートされています)に変換され、2 番目の配列は、 + 1, 3, "2", 2, 1 (数値として降順にソートされています)となっています。 </para> <screen> <![CDATA[ array(2) { - [0]=> array(4) { + [0]=> array(5) { [0]=> string(2) "10" [1]=> int(100) [2]=> int(100) - [3]=> string(1) "a" + [3]=> int(11) + [4]=> string(1) "a" } - [1]=> array(4) { + [1]=> array(5) { [0]=> int(1) [1]=> int(3) [2]=> string(1) "2" - [3]=> int(1) + [3]=> int(2) + [4]=> int(1) } } ]]> @@ -149,14 +157,14 @@ <para> <example> - <title>Sorting database results</title> + <title>データベースの結果をソートする</title> <para> - For this example, each element in the <varname>data</varname> - array represents one row in a table. This type of dataset is typical - of database records. + この例では、配列 <varname>data</varname> の個々の要素が + テーブルのひとつの行を表しています。これは、データベースの + レコードの典型的な形式です。 </para> <para> - Example data: + データの例: </para> <screen> <![CDATA[ @@ -171,8 +179,9 @@ ]]> </screen> <para> - The data as an array, called <varname>data</varname>. This would usually, - for example, be obtained by looping with <function>mysql_fetch_assoc</function>. + データは <varname>data</varname> という名前の配列に格納します。 + これは、例えば <function>mysql_fetch_assoc</function> の結果を + ループさせたりすれば得られます。 </para> <programlisting role="php"> <![CDATA[ @@ -185,33 +194,33 @@ $data[] = array('volume' => 67, 'edition' => 7); ?> ]]> - </programlisting> - <para> - In this example, we will order by <varname>volume</varname> descending, - <varname>edition</varname> ascending. - </para> - <para> - We have an array of rows, but <function>array_multisort</function> - requires an array of columns, so we use the the below code to obtain the - columns, then perform the sorting. - </para> - <programlisting role="php"> + </programlisting> + <para> + この例では、データを <varname>volume</varname> の降順、 + <varname>edition</varname> の昇順に並べ替えます。 + </para> + <para> + 私たちが今もっているのは行方向の配列ですが、 + <function>array_multisort</function> で必要なのは列方向の配列です。 + そこで、以下のコードで列方向の配列を得たあとでソートを行います。 + </para> + <programlisting role="php"> <![CDATA[ <?php -// Obtain a list of columns +// 列方向の配列を得る foreach ($data as $key => $row) { $volume[$key] = $row['volume']; $edition[$key] = $row['edition']; } -// Sort the data with volume descending, edition ascending -// Add $data as the last parameter, to sort by the common key +// データを volume の降順、edition の昇順にソートする。 +// $data を最後のパラメータとして渡し、同じキーでソートする。 array_multisort($volume, SORT_DESC, $edition, SORT_ASC, $data); ?> ]]> </programlisting> <para> - The dataset is now sorted, and will look like this: + データセットの行はソートされ、以下のようになります: </para> <screen> <![CDATA[ @@ -224,24 +233,23 @@ 67 | 2 67 | 7 ]]> - </screen> - </example> - </para> - - <para> - <example> - <title>Case insensitive sorting</title> - <para> - Both <constant>SORT_STRING</constant> and - <constant>SORT_REGULAR</constant> are case sensitive, strings - starting with a capital letter will come before strings starting - with a lowercase letter. + </screen> + </example> </para> + <para> - To perform a case insensitve search, force the sorting order to be - determined by a lowercase copy of the original array. - </para> - <programlisting role="php"> + <example> + <title>大文字・小文字を区別しないソート</title> + <para> + <constant>SORT_STRING</constant> と + <constant>SORT_REGULAR</constant> はどちらも大文字・小文字を区別し、 + 大文字ではじまる文字列が小文字で始まる文字列より前になります。 + </para> + <para> + 大文字・小文字を区別しないためには、元の配列の内容をすべて小文字に + 変換した配列を用意し、それをソートの基準にします。 + </para> + <programlisting role="php"> <![CDATA[ $array = array('Alpha', 'atomic', 'Beta', 'bank'); $array_lowercase = array_map('strtolower', $array); @@ -250,9 +258,9 @@ print_r($array); ]]> - </programlisting> - &example.outputs; - <screen> + </programlisting> + &example.outputs; + <screen> <![CDATA[ Array ( @@ -262,11 +270,12 @@ [3] => Beta ) ]]> - </screen> - </example> - </para> - </refsect1> -</refentry> + </screen> + </example> + </para> + + </refsect1> + </refentry> <!-- Keep this comment at the end of the file Local variables:

« previous php.doc.ja (#1109) next »