Extension:Arrays/tr

Arrays uzantısı (önceden ArrayExtension olarak biliniyordu), diziler üzerinde çalışan ek bir ayrıştırıcı işlevi oluşturur.

İşlevler
Bu uzantı, aşağıdaki ayrıştırıcı işlevlerini tanımlar:

arraydefine
Bu işlev, 'delimiter' ile ayrılmış 'values' listesini kullanarak bir dizi ('key' ile tanımlanan) oluşturur. Değişkene daha sonra diğer işlevler tarafından erişilebilir.

Sözdizimi:

Notlar:
 * values, delimiter ile ayrılmış dizelerin listesidir.
 * Ortaya çıkan dizi, bir dizi dizidir.
 * Varsayılan sınırlayıcı belirtilmemişse ',' değeridir, sınırlayıcı bir dize (sınırlayıcıyı çevreleyen beyaz boşluklar kesilecektir) veya bir Perl normal ifadesi olabilir, örn.  (preg_split sayfasına bakın).
 * Kullanıcılar boş bir dizi tanımlayabilir (örneğe bakın).
 * Kullanıcılar benzersiz, sıralama ve yazdırma gibi seçenekleri belirleyebilir (örneğe bakın).
 * Bir sınırlayıcı da belirtilmediği sürece seçenekler yoksayılır.

Örnekler:

arrayprint
Bu işlev, bir dizinin değerlerini özelleştirilebilir biçimde yazdırır.

Sözdizimi:

Notlar:
 * subject viki bağlantılarını, şablonları ve ayrıştırıcı işlevlerini kabul eder.
 * subject içinde, ' ' boru karakterlerinden kaçmak zorunda değilsiniz. Tüm yapı içinde, pattern aranacak ve her döngünün mevcut (çıkarılan) dizi değeri ile değiştirilecektir. Son olarak, tüm dize ayrıştırılacak ve ayırıcı olarak delimiter ile patlatılacak bir dizi sonuç içine koyulacaktır.
 * Yazdırılması gereken dizinin mevcut olmaması durumunda, boş bir dize döndürülür (uyumluluk modunun bir parçası olan 1.4 alfada sunulmuştur).
 * Varsayılan sınırlayıcı dile bağlıdır, İngilizce için ' ' şeklindedir (2.0'da sunulmuştur, uyumluluk modunun bir parçasıdır).

Örnekler:

arrayindex
Bu işlev, bir dizinin değerini (1$ ile tanımlanır) index konumunda yazdırır.

Sözdizimi:

Notlar:
 * Geçersiz dizin (sayı dışı, sınır dışı) boş bir dize yazdırılmasına neden olur.
 * Dizin 0 tabanlıdır, yani ilk öğenin dizini 0'dır.
 * Negatif dizinler, sondan çok uzakta bir öğe döndürür (örneğin, dizinin son öğesi  olur).
 * Dizinin olmaması, anahtarın dizide olmaması veya değerin boş bir dize olması durumunda default döndürülür.

Örnekler:

arraysize
Bu işlev, bir dizinin boyutunu (öge sayısı) döndürür.

https://php.net/function.count sayfasına bakın Verilen dizinin mevcut olmaması durumunda, işlevin çıkışı sayı yerine geçersiz bir dize olacaktır. This allows to check whether the array exists.

Sözdizimi:

Örnekler:

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

Sözdizimi:

Örnekler:

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.

Sözdizimi:

Notlar:
 * 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.

Örnekler:

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 Sözdizimi:

Notlar:
 * 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.

Örnekler:

Alteration
Functions which alter an array directly instead of creating a new array.

arrayunique
This function converts an array (identified by 'key') into a set (no duplicated members, no empty element).

See https://php.net/function.array-unique Sözdizimi:

Örnek:

arrayreset
This function will unset some or all defined arrays. Sözdizimi:

Notlar:
 * Using arraysize on them will return an empty string instead of, so they are really unset, not empty. To simply empty an array one can use.
 * Prior to version 1.4 alpha ' ' is used to separate several arrays which should be unset.

arraysort
This function sorts an array in the following order. Syntax:
 * - no sort (default)
 * - in descending order (see https://php.net/function.sort)
 * / - in ascending order (see https://php.net/function.rsort)
 * - in random order (see https://php.net/function.array-rand)
 * - in reverse order (see https://php.net/function.array-reverse)

Not:
 * Each array element is being treated as a string, this means numbers might not be ordered as expected.

Örnekler:

Interaction
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. In case they deal with only one array, they simply create a copy of that array. Any non-existant arrays will simply be ignored by these functions.

arraymerge
This function merges values of two or more arrays into a new array (identified by new_key).

See https://php.net/function.array-merge Sözdizimi:

Örnekler:

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

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

Örnek:

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. See https://php.net/function.array-diff

 Syntax: 

Not:
 * This is a set operator, i.e. the returned array is a set without duplicated values.
 * This function can be used to test sub-class relation.

Örnekler:

arrayintersect
This function computes the set theoretic intersection of two or more given arrays. The result array is identified by new_key. See https://php.net/function.array-intersect

Sözdizimi:

Not:
 * This is a set operator, i.e., the returned array is a set without duplicated values.

Örnek:

Yapılandırma
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. This is because in Version 2.0 several breaking changes have been introduced. 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.

Dizi öğelerine yinelemeli erişim
It is possible to iteratively access elements of an array using or.

Using arrayprint
Below is the expected output: More examples can be found at the former Tetherless World Wiki.

Anahtarları yeniden kullanma
Once an array previously defined is printed, the same key can be reused for another array further down the page. As long as this sequence is observed, there is no need to define a unique key for every array.

Loops uzantısı kullanma
For more complex tasks it is possible to loop through an array using the extension.

This would output something like:
 * red
 * green
 * blue

Working with
There are two ways populating an array with semantic data. 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.

Using
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. This is the preferred solution dealing with semantic data in arrays. Details can be found on the semantic-mediawiki.org.

Örnek:

Standart bir sorgu kullanma
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:

Örnek A: To create a list of instances of the class 'Color'

Örnek B: To create a unique list of values of property 'has color'

Örnek 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'

 Notes: 
 * semantic query parameters
 * 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

Working with
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 collect all parameter values which are used by certain pages when they include a given template. We store pairs of template parameter value and pagename. Then we sort the array and print the pairs. If consecutive array elements have the same first part (i.e. the parameter values are identical), the first part is only printed once. Thus we can construct a simple inverted index. The same mechanism could be applied to other problems as well.

Ayrıca bakınız

 * - 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.