Extension:Arrays/ja

The Arrays extension (formerly known as ArrayExtension) creates an additional set of parser functions that operate on arrays.

関数
この拡張機能は以下のパーサー関数を定義します:

arraydefine
この関数は、'delimiter' で区切られた 'values' のリストを用いて、'key' で識別される配列を構築する. この変数は、後で他の関数からアクセスすることができます.

構文:

注記:
 * values is a list of strings separated by delimiter.
 * 結果として得られる配列は、文字列の配列となります.
 * The default delimiter is ',' if not specified, a delimiter can be a string (the white-spaces surrounding delimiter will be trimmed) or a Perl regular expression, e.g.  (see preg_split).
 * ユーザーは空の配列を定義することができます（例参照）.
 * ユーザーは、ユニーク、ソート、プリントなどのオプションを指定することができます（例参照）.
 * オプションはデリミタも指定されない限り無視される.

例:

arrayprint
この関数は、配列の値をカスタマイズ可能なフォーマットで表示します.

構文:

注記:
 * subject accepts wiki links, templates and parser functions.
 * Within the subject, you don't have to escape pipe characters ' '. Within the whole construct, the pattern will be searched and replaced with the current (escaped) array value of each loop. Finally, the whole string will be parsed and put into an array of results which will be imploded with delimiter as separator.
 * In case the array which should be printed doesn't exist, an empty string will be returned (Introduced in 1.4 alpha, part of compatibility mode).
 * The default delimiter is language dependent, for English it is ' ' (Introduced in 2.0, part of compatibility mode).

例:

arrayindex
This function prints the value of an array (identified by key) at position index.

構文:

注記:
 * 無効なインデックス（非数値、境界外）は、空文字列を表示します.
 * The index is 0-based, i.e. the first element's index is 0.
 * Negative indexes will return an element that far from the end (e.g.  would be the arrays last element).
 * default will be returned in case the array doesn't exist, the key doesn't exist within the array or if the value is an empty string.

例:

arraysize
この関数は、配列のサイズ（要素数）を返します.

https://php.net/function.count を参照 In case the given array doesn't exist the output of the function will be a void string instead of a number. これにより、配列が存在するかどうかを確認することができます.

構文:

例:

arraysearch
This function returns the index of the first occurrence of the 'value' in the array (identified by 'key') starting from the position identified by 'index' parameter, and returns an empty string when failed. When yes and/or no specified, this will expand the value set to yes if found, value of no otherwise. See https://php.net/function.array-search

構文:

例:

arraysearcharray
This function searches an array (identified by key) and creates a new array (identified by new_key) from the search with all the results. The search criteria value can be a string or a regular expression. If index is given the search will start there, limit can define the maximum search results. The parameter identified by transform can be used if value is a regular expression. It can transform the result of the matched entries into the new_key array like PHP preg_replace would do it.

構文:

注記:
 * If value is a string, the new_key array will only contain entries of exact this string.
 * Negative index values like  can be used to search the last n entries only.
 * If is available within the wiki, Regex Fun's e modifier can be used within the regex. This has nothing to do with PHPs e modifier (which would be a security breach). With active e modifier the transform string will be parsed after back-refs are inserted, after that it will replace the actual match.

例:

arrayslice
This function extracts a sub-array from an array (identified by 'key') into a new array (identified by 'new_key').

See https://php.net/function.array-slice 構文:

注記:
 * Offset indicates starting point of slice, it can be non-negative number or negative number for backwards index (e.g. the last element of the array's offset is -1). Offset is different from index (which must be non-negative number)
 * Length indicates how many element to extract. If it is omitted, then the sequence will have everything from offset up until the end of the array.
 * If offset is no less than array size, empty array will be returned, if offset if no greater than negative array size, a new array with all elements will be returned.

例:

変更点
新しい配列を作成する代わりに、配列を直接変更する関数です.

arrayunique
この関数は、配列 (キーで識別) を集合 (重複しない、空要素なし) に変換します.

https://php.net/function.array-unique を参照 構文:

例:

arrayreset
この関数は、定義された配列の一部または全部を解除する. 構文:

注記:
 * Using arraysize on them will return an empty string instead of, so they are really unset, not empty. 配列を単純に空にするには、  を使用します.
 * Prior to version 1.4 alpha ' ' is used to separate several arrays which should be unset.

arraysort
この関数は、配列を次の順序でソートする. Syntax:
 * - no sort (default)
 * - 降順に表示（https://php.net/function.sort参照）
 * / - 昇順に表示（https://php.net/function.rsort参照）
 * - 順不同で表示（https://php.net/function.array-rand参照）
 * - 逆順に表示（https://php.net/function.array-reverse参照）

注:
 * 配列の各要素は文字列として扱われるため、数値が期待通りに並ばない可能性があります.

例:

相互作用
Functions which work with more than one array, creating one new array or overwriting an existing one as result. Since version 2.0, these functions can interact with more than just two arrays at a time. 1つの配列しか扱わない場合は、その配列のコピーを作成するだけです. 存在しない配列は、これらの関数では単に無視されます.

arraymerge
この関数は、2つ以上の配列の値を新しい配列（new_keyで識別）に結合します.

https://php.net/function.array-merge を参照 構文:

例:

arrayunion
This function merges values of two or more arrays into a new array (identified by new_key) without duplicated values. 構文:

注記:
 * This is a set operator, i.e., the returned array is a set without duplicated values.
 * This is equal to arraymerge with arrayunique afterwards.

例:

arraydiff
This function computes the (set theoretic) difference of two or more arrays. The result array is identified by new_key. The returned array is a set that contains elements of the first given array (identified by key1) which are not defined within any of the other arrays. https://php.net/function.array-diff を参照

構文:

注:
 * これは集合演算子であり、返される配列は重複する値を含まない集合となります.
 * この関数は、サブクラス関係をテストするために使用することができます.

例:

arrayintersect
この関数は，2つ以上の配列の集合論的な交点を計算する. The result array is identified by new_key. https://php.net/function.array-intersect を参照

構文:

注:
 * これは集合演算子であり、返される配列は重複した値を持たない集合である.

例:

設定
Arrays 2.0 introduces two configuration variables:


 * $egArraysCompatibilityMode
 * ($egArrayExtensionCompatbilityMode in 1.4 alpha) Set to true, this will activate the compatibility mode which will bring back the behavior of the old ArrayExtension 1.3.2 as far as possible. これは、Version 2.0において、いくつかの破壊的な変更が導入されたためです. So using this compatibility mode allows a smooth switch from 1.x to 2.x Arrays extension. By default, compatibility mode is inactive. For a list which changes are effected by this, see Extension:Arrays/Pre 2.0 Documentation#Differences compared to Arrays 2.0. If you have been using the old ArrayExtension within your wiki before, you might want to take a look at that list and adjust your templates before switching to Arrays without compatibility mode.


 * $egArraysExpansionEscapeTemplates
 * Contains a key-value pair list of characters that should be replaced by a template or parser function call within array values included into an . By replacing these special characters before including the values into the string which is being expanded afterwards, array values can't distract the surrounding MW code. Otherwise the array values themselves would be parsed as well. By default this will escape the following characters with the following template or parser function calls:
 * =  ( "Template:=" should print ' ' )
 * =  ( "Template:!" should print ' ' )
 * Starting with MW 1.24.0 it is no longer necessary to create "Template:!" since its purpose is served by the new  magic word.
 * =  ( "Template:((" should print ' ' )
 * =  ( "Template:))" should print ' ' )
 * Make sure these templates or parser functions exist within your wiki or change this variable accordingly. If this is not set up properly,  might print unexpected values in case on of these character sequences is being used within array values.
 * $egArraysExpansionEscapeTemplates also can simply be set to null, in this case it switches back to pre 2.0 behavior where array values with these character sequences did break the given subject code within . If the compatibility mode is active, this will always be treated as set to null.

Iteratively accessing array elements
It is possible to iteratively access elements of an array using or.

arrayprintを使用
以下は、期待される出力です. More examples can be found at the former Tetherless World Wiki.

キーの再利用
一度定義した配列をプリントすれば、同じキーをさらに下の階層の配列に再利用することができます. この順序を守る限り、すべてのアレイに一意のキーを定義する必要はありません.

ループ拡張機能の使用
より複雑なタスクのために、拡張機能を使って配列の中をループすることが可能である.

次のようなものを出力します：


 * red
 * green
 * blue

との連携
配列にセマンティックデータを入力する方法は2つあります. The first solution, using Semantic Result Formats is faster and more reliable, also works with complex data sets including record data and multiple values for one property.

を使用
Semantic Result Formats (SRF) introduces the Array format in version 1.6.1. It can be used to query data which will automatically be stored within an Extension:Arrays array. これは、配列内のセマンティックデータを扱うのに好ましいソリューションです. 詳細はsemantic-mediawiki.orgで確認できます.

例:

標準クエリの使用
If you can't use the SRF solution above, Arrays also allows to populate an array using a SMW query result of the list format:

例 A: クラス 'Color' のインスタンスのリストを作成するには

例 B: プロパティ 'has color' の値の一意なリストを作成するには

例 C: To deal with 2D array generated by SWM query (e.g. record-type property) given a 2D array "red;#da2021, yellow;#fcff00, green;#00ff00"

1. create an array 'colors'

2. split the first element of 'colors' into another array 'colors0'

注記:
 * セマンティッククエリパラメータ
 * option is used to exhaust all returned results of the semantic query
 * option is used to set the separator for entries of the results
 * option to cut off the page column

との連携
In a similar way as described above for SMW the Arrays extension can be used to store results of a DPL query. In the example, we show how a result list can be inverted. 特定のページが特定のテンプレートを含むときに使用されるすべてのパラメータ値を収集します. We store pairs of template parameter value and pagename. そして、配列をソートしてペアを表示します. 連続した配列要素の最初の部分が同じ（つまりパラメータ値が同じ）場合、最初の部分は一度だけ表示されます. このように、単純な転置インデックスを構成することができる. The same mechanism could be applied to other problems as well.

関連項目

 * - very similar extension for the use of hash tables in MediaWiki.
 * - includes more than fifty functions for working with arrays using the PHP syntax.
 * - offers the parser function . Since input and output are handled by the same function, it does away with the need to define a key.
 * - provides a set of parser functions to operate on multidimensional and associative arrays.
 * - Scribunto which allows you to embed Lua scripts into wikipages, which provides arrays and standard imperative programming language control flow.
 * - Scribunto which allows you to embed Lua scripts into wikipages, which provides arrays and standard imperative programming language control flow.